comparison src/http/modules/ngx_http_gzip_filter_module.c @ 9061:fcb2333c9982

Gzip: compatibility with recent zlib-ng versions. It now uses custom alloc_aligned() wrapper for all allocations, therefore all allocations are larger than expected by (64 + sizeof(void*)). Further, they are seen as allocations of 1 element. Relevant calculations were adjusted to reflect this, and state allocation is now protected with a flag to avoid misinterpreting other allocations as the zlib deflate_state allocation. Further, it no longer forces window bits to 13 on compression level 1, so the comment was adjusted to reflect this.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 27 Mar 2023 21:25:05 +0300
parents d26db4f82d7d
children
comparison
equal deleted inserted replaced
9059:d1cf09451ae8 9061:fcb2333c9982
55 unsigned redo:1; 55 unsigned redo:1;
56 unsigned done:1; 56 unsigned done:1;
57 unsigned nomem:1; 57 unsigned nomem:1;
58 unsigned buffering:1; 58 unsigned buffering:1;
59 unsigned zlib_ng:1; 59 unsigned zlib_ng:1;
60 unsigned state_allocated:1;
60 61
61 size_t zin; 62 size_t zin;
62 size_t zout; 63 size_t zout;
63 64
64 z_stream zstream; 65 z_stream zstream;
512 + (1 << (memlevel + 9)); 513 + (1 << (memlevel + 9));
513 514
514 } else { 515 } else {
515 /* 516 /*
516 * Another zlib variant, https://github.com/zlib-ng/zlib-ng. 517 * Another zlib variant, https://github.com/zlib-ng/zlib-ng.
517 * It forces window bits to 13 for fast compression level, 518 * It used to force window bits to 13 for fast compression level,
518 * uses 16-byte padding in one of window-sized buffers, and 519 * uses (64 + sizeof(void*)) additional space on all allocations
519 * uses 128K hash. 520 * for alignment, 16-byte padding in one of window-sized buffers,
521 * and 128K hash.
520 */ 522 */
521 523
522 if (conf->level == 1) { 524 if (conf->level == 1) {
523 wbits = ngx_max(wbits, 13); 525 wbits = ngx_max(wbits, 13);
524 } 526 }
525 527
526 ctx->allocated = 8192 + 16 + (1 << (wbits + 2)) 528 ctx->allocated = 8192 + 16 + (1 << (wbits + 2))
527 + 131072 + (1 << (memlevel + 8)); 529 + 131072 + (1 << (memlevel + 8))
530 + 4 * (64 + sizeof(void*));
528 ctx->zlib_ng = 1; 531 ctx->zlib_ng = 1;
529 } 532 }
530 } 533 }
531 534
532 535
924 void *p; 927 void *p;
925 ngx_uint_t alloc; 928 ngx_uint_t alloc;
926 929
927 alloc = items * size; 930 alloc = items * size;
928 931
929 if (items == 1 && alloc % 512 != 0 && alloc < 8192) { 932 if (items == 1 && alloc % 512 != 0 && alloc < 8192
930 933 && !ctx->state_allocated)
934 {
931 /* 935 /*
932 * The zlib deflate_state allocation, it takes about 6K, 936 * The zlib deflate_state allocation, it takes about 6K,
933 * we allocate 8K. Other allocations are divisible by 512. 937 * we allocate 8K. Other allocations are divisible by 512.
934 */ 938 */
939
940 ctx->state_allocated = 1;
935 941
936 alloc = 8192; 942 alloc = 8192;
937 } 943 }
938 944
939 if (alloc <= ctx->allocated) { 945 if (alloc <= ctx->allocated) {