summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-05-01 14:22:49 -0400
committerNick Mathewson <nickm@torproject.org>2017-05-01 14:22:49 -0400
commit4837421d7cb6bcc52d5ffd09527ac786759b3b0a (patch)
tree0cadcd1535e1a46d75f9fd11f07e06fed2e9aeea /src/common
parentd6dd05f6d8171191cfc2ea331ef6e1a89318decf (diff)
parent0672b33f1e0ca160563841aaf7af87adbacd95d3 (diff)
downloadtor-4837421d7cb6bcc52d5ffd09527ac786759b3b0a.tar.gz
tor-4837421d7cb6bcc52d5ffd09527ac786759b3b0a.zip
Merge remote-tracking branch 'ahf/bugs/21665'
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compress.c4
-rw-r--r--src/common/compress_lzma.c13
2 files changed, 9 insertions, 8 deletions
diff --git a/src/common/compress.c b/src/common/compress.c
index 8502dee25c..738df9f185 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -255,8 +255,8 @@ detect_compression_method(const char *in, size_t in_len)
} else if (in_len > 2 && (in[0] & 0x0f) == 8 &&
(ntohs(get_uint16(in)) % 31) == 0) {
return ZLIB_METHOD;
- } else if (in_len > 3 &&
- fast_memeq(in, "\x5d\x00\x00\x00", 4)) {
+ } else if (in_len > 2 &&
+ fast_memeq(in, "\x5d\x00\x00", 3)) {
return LZMA_METHOD;
} else if (in_len > 3 &&
fast_memeq(in, "\x28\xb5\x2f\xfd", 4)) {
diff --git a/src/common/compress_lzma.c b/src/common/compress_lzma.c
index b721bae8aa..b5393a6ba6 100644
--- a/src/common/compress_lzma.c
+++ b/src/common/compress_lzma.c
@@ -22,6 +22,9 @@
#include <lzma.h>
#endif
+/** The maximum amount of memory we allow the LZMA decoder to use, in bytes. */
+#define MEMORY_LIMIT (16 * 1024 * 1024)
+
/** Total number of bytes allocated for LZMA state. */
static atomic_counter_t total_lzma_allocation;
@@ -33,9 +36,9 @@ memory_level(compression_level_t level)
switch (level) {
default:
case BEST_COMPRESSION:
- case HIGH_COMPRESSION: return 9;
- case MEDIUM_COMPRESSION: return 6;
- case LOW_COMPRESSION: return 3;
+ case HIGH_COMPRESSION: return 6;
+ case MEDIUM_COMPRESSION: return 4;
+ case LOW_COMPRESSION: return 2;
}
}
@@ -191,9 +194,7 @@ tor_lzma_compress_new(int compress,
goto err;
}
} else {
- // FIXME(ahf): This should be something more sensible than
- // UINT64_MAX: See #21665.
- retval = lzma_alone_decoder(&result->stream, UINT64_MAX);
+ retval = lzma_alone_decoder(&result->stream, MEMORY_LIMIT);
if (retval != LZMA_OK) {
log_warn(LD_GENERAL, "Error from LZMA decoder: %s (%u).",