]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
liblzma 5.0 provides a better solution for memory usage limit in decoding.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 31 Dec 2010 11:30:20 +0000 (06:30 -0500)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Fri, 31 Dec 2010 11:30:20 +0000 (06:30 -0500)
SVN-Revision: 2848

libarchive/archive_read_support_compression_xz.c
libarchive/archive_read_support_format_xar.c

index 23f347cf45782c3f65db1704111667370aef19c7..720bc8a2cd9922fa239de1ab528c92afdf66a145 100644 (file)
@@ -69,6 +69,14 @@ struct private_data {
        int64_t          member_out;
 };
 
+#if LZMA_VERSION_MAJOR >= 5
+/* Effectively disable the limiter. */
+#define LZMA_MEMLIMIT  UINT64_MAX
+#else
+/* NOTE: This needs to check memory size which running system has. */
+#define LZMA_MEMLIMIT  (1U << 30)
+#endif
+
 /* Combined lzip/lzma/xz filter */
 static ssize_t xz_filter_read(struct archive_read_filter *, const void **);
 static int     xz_filter_close(struct archive_read_filter *);
@@ -516,18 +524,14 @@ xz_lzma_bidder_init(struct archive_read_filter *self)
        } else
                state->in_stream = 1;
 
-       /* Initialize compression library.
-        * TODO: I don't know what value is best for memlimit.
-        *       maybe, it needs to check memory size which
-        *       running system has.
-        */
+       /* Initialize compression library. */
        if (self->code == ARCHIVE_COMPRESSION_XZ)
                ret = lzma_stream_decoder(&(state->stream),
-                   (1U << 30),/* memlimit */
+                   LZMA_MEMLIMIT,/* memlimit */
                    LZMA_CONCATENATED);
        else
                ret = lzma_alone_decoder(&(state->stream),
-                   (1U << 30));/* memlimit */
+                   LZMA_MEMLIMIT);/* memlimit */
 
        if (ret == LZMA_OK)
                return (ARCHIVE_OK);
index 035e1ef070597ee0f64459b49f0cf38bcc2831cc..b85a3f542f82dbd537f3bff2bae34c9734c739ab 100644 (file)
@@ -1378,6 +1378,13 @@ decompression_init(struct archive_read *a, enum enctype encoding)
                break;
 #endif
 #if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA)
+#if LZMA_VERSION_MAJOR >= 5
+/* Effectively disable the limiter. */
+#define LZMA_MEMLIMIT   UINT64_MAX
+#else
+/* NOTE: This needs to check memory size which running system has. */
+#define LZMA_MEMLIMIT   (1U << 30)
+#endif
        case XZ:
        case LZMA:
                if (xar->lzstream_valid) {
@@ -1386,11 +1393,11 @@ decompression_init(struct archive_read *a, enum enctype encoding)
                }
                if (xar->entry_encoding == XZ)
                        r = lzma_stream_decoder(&(xar->lzstream),
-                           (1U << 30),/* memlimit */
+                           LZMA_MEMLIMIT,/* memlimit */
                            LZMA_CONCATENATED);
                else
                        r = lzma_alone_decoder(&(xar->lzstream),
-                           (1U << 30));/* memlimit */
+                           LZMA_MEMLIMIT);/* memlimit */
                if (r != LZMA_OK) {
                        switch (r) {
                        case LZMA_MEM_ERROR: