Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: net/websockets/websocket_deflater.cc

Issue 2690623003: Update zlib to 1.2.11 (Closed)
Patch Set: Drop the inflater change, improve the deflater comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/zlib/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/websockets/websocket_deflater.h" 5 #include "net/websockets/websocket_deflater.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <deque> 9 #include <deque>
10 #include <vector> 10 #include <vector>
(...skipping 13 matching lines...) Expand all
24 stream_.reset(NULL); 24 stream_.reset(NULL);
25 } 25 }
26 } 26 }
27 27
28 bool WebSocketDeflater::Initialize(int window_bits) { 28 bool WebSocketDeflater::Initialize(int window_bits) {
29 DCHECK(!stream_); 29 DCHECK(!stream_);
30 stream_.reset(new z_stream); 30 stream_.reset(new z_stream);
31 31
32 DCHECK_LE(8, window_bits); 32 DCHECK_LE(8, window_bits);
33 DCHECK_GE(15, window_bits); 33 DCHECK_GE(15, window_bits);
34
35 // Use a negative value to compress a raw deflate stream.
36 //
37 // Upgrade window_bits = 8 to 9 because zlib is unable to compress at
38 // window_bits = 8. Historically, zlib has silently increased the window size
39 // during compression in this case, although this is no longer done for raw
40 // deflate streams since zlib 1.2.9.
41 //
42 // Because of a zlib deflate quirk, back-references will not use the entire
43 // range of 1 << window_bits, but will instead use a restricted range of (1 <<
44 // window_bits) - 262. With an increased window_bits = 9, back-references will
45 // be within a range of 250. These can still be decompressed with window_bits
46 // = 8 and the 256-byte window used there.
47 //
48 // Both the requirement to do this upgrade and the ability to compress with
49 // window_bits = 9 while expecting a decompressor to function with window_bits
50 // = 8 are quite specific to zlib's particular deflate implementation, but not
51 // specific to any particular inflate implementation.
52 //
53 // See https://crbug.com/691074
54 window_bits = -std::max(window_bits, 9);
55
34 memset(stream_.get(), 0, sizeof(*stream_)); 56 memset(stream_.get(), 0, sizeof(*stream_));
35 int result = deflateInit2(stream_.get(), 57 int result = deflateInit2(stream_.get(),
36 Z_DEFAULT_COMPRESSION, 58 Z_DEFAULT_COMPRESSION,
37 Z_DEFLATED, 59 Z_DEFLATED,
38 -window_bits, // Negative value for raw deflate 60 window_bits,
39 8, // default mem level 61 8, // default mem level
40 Z_DEFAULT_STRATEGY); 62 Z_DEFAULT_STRATEGY);
41 if (result != Z_OK) { 63 if (result != Z_OK) {
42 deflateEnd(stream_.get()); 64 deflateEnd(stream_.get());
43 stream_.reset(); 65 stream_.reset();
44 return false; 66 return false;
45 } 67 }
46 const size_t kFixedBufferSize = 4096; 68 const size_t kFixedBufferSize = 4096;
47 fixed_buffer_.resize(kFixedBufferSize); 69 fixed_buffer_.resize(kFixedBufferSize);
48 return true; 70 return true;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 stream_->next_out = reinterpret_cast<Bytef*>(&fixed_buffer_[0]); 141 stream_->next_out = reinterpret_cast<Bytef*>(&fixed_buffer_[0]);
120 stream_->avail_out = fixed_buffer_.size(); 142 stream_->avail_out = fixed_buffer_.size();
121 result = deflate(stream_.get(), flush); 143 result = deflate(stream_.get(), flush);
122 size_t size = fixed_buffer_.size() - stream_->avail_out; 144 size_t size = fixed_buffer_.size() - stream_->avail_out;
123 buffer_.insert(buffer_.end(), &fixed_buffer_[0], &fixed_buffer_[0] + size); 145 buffer_.insert(buffer_.end(), &fixed_buffer_[0], &fixed_buffer_[0] + size);
124 } while (result == Z_OK); 146 } while (result == Z_OK);
125 return result; 147 return result;
126 } 148 }
127 149
128 } // namespace net 150 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | third_party/zlib/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698