Skip to content

Commit 5f15595

Browse files
authored
Fix integer overflow in compress plugin for large file compression (#12478)
The compress plugin was crashing when compressing large files due to integer overflow in the downstream_length tracking variable: ``` [ET_NET 4] ERROR: <InkAPI.cc:250 (TSError)> [/trafficserver/plugins/compress/compress.cc:507] [brotli_transform_finish] ERROR: brotli-transform: output lengths don't match (-2102735855, 2192231441) Fatal: /trafficserver/src/api/InkIOCoreAPI.cc:356: failed assertion `nbytes >= 0` traffic_server: received signal 6 (Aborted) ``` The issue occurred when compressing files larger than ~2GB, causing the 32-bit signed downstream_length to overflow and wrap to negative values, while the compression libraries' output counters (uLong/size_t) reported correct values. Changes: - Upgraded downstream_length from 'int' to 'int64_t' to handle large files - Updated printf format specifiers from %d to %ld for int64_t values
1 parent b13b985 commit 5f15595

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

plugins/compress/compress.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
#include <cstring>
25+
#include <cinttypes>
2526
#include <zlib.h>
2627

2728
#include "ts/apidefs.h"
@@ -539,7 +540,7 @@ gzip_transform_finish(Data *data)
539540
}
540541

541542
if (data->downstream_length != static_cast<int64_t>(data->zstrm.total_out)) {
542-
error("gzip-transform: output lengths don't match (%d, %ld)", data->downstream_length, data->zstrm.total_out);
543+
error("gzip-transform: output lengths don't match (%" PRId64 ", %lu)", data->downstream_length, data->zstrm.total_out);
543544
}
544545

545546
debug("gzip-transform: Finished gzip");
@@ -564,7 +565,7 @@ brotli_transform_finish(Data *data)
564565
}
565566

566567
if (data->downstream_length != static_cast<int64_t>(data->bstrm.total_out)) {
567-
error("brotli-transform: output lengths don't match (%d, %ld)", data->downstream_length, data->bstrm.total_out);
568+
error("brotli-transform: output lengths don't match (%" PRId64 ", %zu)", data->downstream_length, data->bstrm.total_out);
568569
}
569570

570571
debug("brotli-transform: Finished brotli");

plugins/compress/misc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ using Data = struct {
7676
TSVIO downstream_vio;
7777
TSIOBuffer downstream_buffer;
7878
TSIOBufferReader downstream_reader;
79-
int downstream_length;
79+
int64_t downstream_length;
8080
z_stream zstrm;
8181
enum transform_state state;
8282
int compression_type;

0 commit comments

Comments
 (0)