1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-30 02:50:07 +03:00

xmlIO: Fix reading from non-regular files like pipes

Commit 7e14c05d removed unnecessary copying of uncompressed input
through zlib or xzlib. This broke input from non-regular files like
pipes which can't be reopened. Try to detect such files by checking
whether they're seekable and always pipe them through zlib or xzlib.

Also remove seemingly unnecessary calls to gzread and gzrewind to
support unseekable files.

Fixes https://gitlab.gnome.org/GNOME/libxslt/-/issues/124.
This commit is contained in:
Nick Wellnhofer 2024-11-06 16:42:05 +01:00
parent 459146140a
commit 1e4d8c55f0

19
xmlIO.c

@ -1068,7 +1068,13 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename,
if (xzStream == NULL) {
close(fd);
} else {
if (__libxml2_xzcompressed(xzStream) > 0) {
/*
* Non-regular files like pipes can't be reopened.
* If a file isn't seekable, we pipe uncompressed
* input through xzlib.
*/
if ((lseek(fd, 0, SEEK_CUR) < 0) ||
(__libxml2_xzcompressed(xzStream) > 0)) {
buf->context = xzStream;
buf->readcallback = xmlXzfileRead;
buf->closecallback = xmlXzfileClose;
@ -1095,12 +1101,13 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename,
if (gzStream == NULL) {
close(fd);
} else {
char buff4[4];
if ((gzread(gzStream, buff4, 4) > 0) &&
/*
* Non-regular files like pipes can't be reopened.
* If a file isn't seekable, we pipe uncompressed
* input through zlib.
*/
if ((lseek(fd, 0, SEEK_CUR) < 0) ||
(gzdirect(gzStream) == 0)) {
gzrewind(gzStream);
buf->context = gzStream;
buf->readcallback = xmlGzfileRead;
buf->closecallback = xmlGzfileClose;