You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.7 KiB

  1. From 9b9531d90dfd8a334958d23394afafd0185bfa21 Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Sat, 28 Mar 2015 12:20:33 +0100
  4. Subject: [PATCH 8/9] BUG/MINOR: compression: consider the expansion factor in
  5. init
  6. When checking if the buffer is large enough, we used to rely on a fixed
  7. size that was "apparently" enough. We need to consider the expansion
  8. factor of deflate-encoded streams instead, which is of 5 bytes per 32kB.
  9. The previous value was OK till 128kB buffers but became wrong past that.
  10. It's totally harmless since we always keep the reserve when compressiong,
  11. so there's 1kB or so available, which is enough for buffers as large as
  12. 6.5 MB, but better fix the check anyway.
  13. This fix could be backported into 1.5 since compression was added there.
  14. (cherry picked from commit 2aee2215c908c6997addcd1714b5b10f73c0703d)
  15. ---
  16. src/compression.c | 9 ++++++---
  17. 1 file changed, 6 insertions(+), 3 deletions(-)
  18. diff --git a/src/compression.c b/src/compression.c
  19. index 3d6085e..d55f14e 100644
  20. --- a/src/compression.c
  21. +++ b/src/compression.c
  22. @@ -130,9 +130,12 @@ int http_compression_buffer_init(struct session *s, struct buffer *in, struct bu
  23. {
  24. int left;
  25. - /* not enough space */
  26. - if (in->size - buffer_len(in) < 40)
  27. - return -1;
  28. + /* output stream requires at least 10 bytes for the gzip header, plus
  29. + * at least 8 bytes for the gzip trailer (crc+len), plus a possible
  30. + * plus at most 5 bytes per 32kB block and 2 bytes to close the stream.
  31. + */
  32. + if (in->size - buffer_len(in) < 20 + 5 * ((in->i + 32767) >> 15))
  33. + return -1;
  34. /* We start by copying the current buffer's pending outgoing data into
  35. * a new temporary buffer that we initialize with a new empty chunk.
  36. --
  37. 2.0.5