Skip to content

Commit a3afc31

Browse files
committed
xmlIO: Fix reading from non-regular files like pipes
Commit 7e14c05 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.
1 parent f228c6f commit a3afc31

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

xmlIO.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,13 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
12101210
if (xzStream == NULL) {
12111211
close(fd);
12121212
} else {
1213-
if (__libxml2_xzcompressed(xzStream) > 0) {
1213+
/*
1214+
* Non-regular files like pipes can't be reopened.
1215+
* If a file isn't seekable, we pipe uncompressed
1216+
* input through xzlib.
1217+
*/
1218+
if ((lseek(fd, 0, SEEK_CUR) < 0) ||
1219+
(__libxml2_xzcompressed(xzStream) > 0)) {
12141220
buf->context = xzStream;
12151221
buf->readcallback = xmlXzfileRead;
12161222
buf->closecallback = xmlXzfileClose;
@@ -1237,12 +1243,13 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
12371243
if (gzStream == NULL) {
12381244
close(fd);
12391245
} else {
1240-
char buff4[4];
1241-
1242-
if ((gzread(gzStream, buff4, 4) > 0) &&
1246+
/*
1247+
* Non-regular files like pipes can't be reopened.
1248+
* If a file isn't seekable, we pipe uncompressed
1249+
* input through zlib.
1250+
*/
1251+
if ((lseek(fd, 0, SEEK_CUR) < 0) ||
12431252
(gzdirect(gzStream) == 0)) {
1244-
gzrewind(gzStream);
1245-
12461253
buf->context = gzStream;
12471254
buf->readcallback = xmlGzfileRead;
12481255
buf->closecallback = xmlGzfileClose;

0 commit comments

Comments
 (0)