mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2026-01-26 21:41:34 +03:00
io: Fix detection of compressed streams
Make sure that we don't try to open uncompressed streams with a compression handler in copying mode.
This commit is contained in:
56
xmlIO.c
56
xmlIO.c
@@ -1048,7 +1048,7 @@ xmlBufferWrite (void * context, const char * buffer, int len) {
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlGzfileMatch (const char *filename ATTRIBUTE_UNUSED) {
|
xmlGzfileMatch (const char *filename ATTRIBUTE_UNUSED) {
|
||||||
return(1);
|
return(strcmp(filename, "-") != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1254,7 +1254,7 @@ xmlGzfileClose (void * context) {
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
xmlXzfileMatch (const char *filename ATTRIBUTE_UNUSED) {
|
xmlXzfileMatch (const char *filename ATTRIBUTE_UNUSED) {
|
||||||
return(1);
|
return(strcmp(filename, "-") != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -2148,47 +2148,43 @@ xmlInputDefaultOpen(xmlParserInputBufferPtr buf, const char *filename) {
|
|||||||
|
|
||||||
#ifdef LIBXML_LZMA_ENABLED
|
#ifdef LIBXML_LZMA_ENABLED
|
||||||
if (xmlXzfileMatch(filename)) {
|
if (xmlXzfileMatch(filename)) {
|
||||||
buf->context = xmlXzfileOpen(filename);
|
void *context = xmlXzfileOpen(filename);
|
||||||
|
|
||||||
if (buf->context != NULL) {
|
if (context != NULL) {
|
||||||
buf->readcallback = xmlXzfileRead;
|
if (__libxml2_xzcompressed(context) > 0) {
|
||||||
buf->closecallback = xmlXzfileClose;
|
buf->context = context;
|
||||||
|
buf->readcallback = xmlXzfileRead;
|
||||||
if (strcmp(filename, "-") != 0)
|
buf->closecallback = xmlXzfileClose;
|
||||||
buf->compressed = __libxml2_xzcompressed(buf->context);
|
buf->compressed = __libxml2_xzcompressed(buf->context);
|
||||||
|
|
||||||
return(XML_ERR_OK);
|
return(XML_ERR_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
xmlXzfileClose(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* LIBXML_LZMA_ENABLED */
|
#endif /* LIBXML_LZMA_ENABLED */
|
||||||
|
|
||||||
#ifdef LIBXML_ZLIB_ENABLED
|
#ifdef LIBXML_ZLIB_ENABLED
|
||||||
if (xmlGzfileMatch(filename)) {
|
if (xmlGzfileMatch(filename)) {
|
||||||
buf->context = xmlGzfileOpen(filename);
|
void *context = xmlGzfileOpen(filename);
|
||||||
|
|
||||||
if (buf->context != NULL) {
|
if (context != NULL) {
|
||||||
buf->readcallback = xmlGzfileRead;
|
char buff4[4];
|
||||||
buf->closecallback = xmlGzfileClose;
|
|
||||||
|
|
||||||
if (strcmp(filename, "-") != 0) {
|
if ((gzread(context, buff4, 4) > 0) &&
|
||||||
#if defined(ZLIB_VERNUM) && ZLIB_VERNUM >= 0x1230
|
(gzdirect(context) == 0)) {
|
||||||
buf->compressed = !gzdirect(buf->context);
|
gzrewind(context);
|
||||||
#else
|
|
||||||
if (((z_stream *)context)->avail_in > 4) {
|
buf->context = context;
|
||||||
char *cptr, buff4[4];
|
buf->readcallback = xmlGzfileRead;
|
||||||
cptr = (char *) ((z_stream *)buf->context)->next_in;
|
buf->closecallback = xmlGzfileClose;
|
||||||
if (gzread(context, buff4, 4) == 4) {
|
buf->compressed = 1;
|
||||||
if (strncmp(buff4, cptr, 4) == 0)
|
|
||||||
buf->compressed = 0;
|
return(XML_ERR_OK);
|
||||||
else
|
|
||||||
buf->compressed = 1;
|
|
||||||
gzrewind(context);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(XML_ERR_OK);
|
xmlGzfileClose(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* LIBXML_ZLIB_ENABLED */
|
#endif /* LIBXML_ZLIB_ENABLED */
|
||||||
|
|||||||
18
xzlib.c
18
xzlib.c
@@ -195,6 +195,12 @@ xz_compressed(xzFile f) {
|
|||||||
case COPY:
|
case COPY:
|
||||||
return(0);
|
return(0);
|
||||||
case GZIP:
|
case GZIP:
|
||||||
|
#ifdef LIBXML_ZLIB_ENABLED
|
||||||
|
/* Don't use lzma for gzip */
|
||||||
|
return(0);
|
||||||
|
#else
|
||||||
|
return(1);
|
||||||
|
#endif
|
||||||
case LZMA:
|
case LZMA:
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
@@ -207,11 +213,6 @@ __libxml2_xzopen(const char *path, const char *mode)
|
|||||||
return xz_open(path, -1, mode);
|
return xz_open(path, -1, mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
__libxml2_xzcompressed(xzFile f) {
|
|
||||||
return xz_compressed(f);
|
|
||||||
}
|
|
||||||
|
|
||||||
xzFile
|
xzFile
|
||||||
__libxml2_xzdopen(int fd, const char *mode)
|
__libxml2_xzdopen(int fd, const char *mode)
|
||||||
{
|
{
|
||||||
@@ -700,6 +701,13 @@ xz_skip(xz_statep state, uint64_t len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
__libxml2_xzcompressed(xzFile f) {
|
||||||
|
xz_head(f);
|
||||||
|
|
||||||
|
return xz_compressed(f);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
__libxml2_xzread(xzFile file, void *buf, unsigned len)
|
__libxml2_xzread(xzFile file, void *buf, unsigned len)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user