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

Side by Side Diff: net/filter/gzip_source_stream.h

Issue 2604233002: Fix bug in deflate code. (Closed)
Patch Set: Cleanups Created 3 years, 11 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 | net/filter/gzip_source_stream.cc » ('j') | net/filter/gzip_source_stream.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #ifndef NET_FILTER_GZIP_SOURCE_STREAM_H_ 5 #ifndef NET_FILTER_GZIP_SOURCE_STREAM_H_
6 #define NET_FILTER_GZIP_SOURCE_STREAM_H_ 6 #define NET_FILTER_GZIP_SOURCE_STREAM_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 26 matching lines...) Expand all
37 std::unique_ptr<SourceStream> previous, 37 std::unique_ptr<SourceStream> previous,
38 SourceStream::SourceType type); 38 SourceStream::SourceType type);
39 39
40 private: 40 private:
41 enum InputState { 41 enum InputState {
42 // Starts processing the input stream. Checks whether the stream is valid 42 // Starts processing the input stream. Checks whether the stream is valid
43 // and whether a fallback to plain data is needed. 43 // and whether a fallback to plain data is needed.
44 STATE_START, 44 STATE_START,
45 // Gzip header of the input stream is being processed. 45 // Gzip header of the input stream is being processed.
46 STATE_GZIP_HEADER, 46 STATE_GZIP_HEADER,
47 // Deflate responses may or may not have a zlib header. In this state until
xunjieli 2017/01/03 16:21:17 For future reference, could you add a link to bug
mmenke 2017/01/03 18:25:42 SGTM, Done.
48 // enough has been inflated that this stream most likely has a zlib header,
49 // or until a zlib header has been added. Data is appended to |replay_data_|
50 // in case it needs to be replayed after adding a header.
51 STATE_SNIFFING_DEFLATE_HEADER,
52 // If a zlib header has to be added to the response, this state will replay
53 // data passed to inflate before it was determined that no zlib header was
54 // present.
55 STATE_REPLAY_DATA,
47 // The input stream is being decoded. 56 // The input stream is being decoded.
48 STATE_COMPRESSED_BODY, 57 STATE_COMPRESSED_BODY,
49 // Gzip footer of the input stream is being processed. 58 // Gzip footer of the input stream is being processed.
50 STATE_GZIP_FOOTER, 59 STATE_GZIP_FOOTER,
51 // The input stream is being passed through undecoded. 60 // The input stream is being passed through undecoded.
52 STATE_UNCOMPRESSED_BODY, 61 STATE_UNCOMPRESSED_BODY,
53 }; 62 };
54 63
55 GzipSourceStream(std::unique_ptr<SourceStream> previous, 64 GzipSourceStream(std::unique_ptr<SourceStream> previous,
56 SourceStream::SourceType type); 65 SourceStream::SourceType type);
(...skipping 20 matching lines...) Expand all
77 // Returns whether this stream looks like it could be plain text (ie, not 86 // Returns whether this stream looks like it could be plain text (ie, not
78 // actually gzipped). Right now this uses an extremely simple heuristic; see 87 // actually gzipped). Right now this uses an extremely simple heuristic; see
79 // the source for details. This method checks the first byte of the stream. 88 // the source for details. This method checks the first byte of the stream.
80 bool ShouldFallbackToPlain(char first_byte); 89 bool ShouldFallbackToPlain(char first_byte);
81 90
82 // The control block of zlib which actually does the decoding. 91 // The control block of zlib which actually does the decoding.
83 // This data structure is initialized by Init and updated only by 92 // This data structure is initialized by Init and updated only by
84 // FilterData(), with InsertZlibHeader() being the exception as a workaround. 93 // FilterData(), with InsertZlibHeader() being the exception as a workaround.
85 std::unique_ptr<z_stream> zlib_stream_; 94 std::unique_ptr<z_stream> zlib_stream_;
86 95
87 // A flag used by FilterData() to record whether we've successfully added 96 // While in STATE_SNIFFING_DEFLATE_HEADER, it may be determined that a zlib
88 // a zlib header to this stream. 97 // header needs to be added, and all received data needs to be replayed. In
89 bool zlib_header_added_; 98 // that case, this buffer holds the data to be replayed.
99 std::string replay_data_;
90 100
91 // Used to parse the gzip header in gzip stream. 101 // Used to parse the gzip header in gzip stream.
92 // It is used when the decoding mode is GZIP_SOURCE_STREAM_GZIP. 102 // It is used when the decoding mode is GZIP_SOURCE_STREAM_GZIP.
93 GZipHeader gzip_header_; 103 GZipHeader gzip_header_;
94 104
95 // Tracks how many bytes of gzip footer are yet to be filtered. 105 // Tracks how many bytes of gzip footer are yet to be filtered.
96 size_t gzip_footer_bytes_left_; 106 size_t gzip_footer_bytes_left_;
97 107
98 // Tracks the state of the input stream. 108 // Tracks the state of the input stream.
99 InputState input_state_; 109 InputState input_state_;
100 110
111 // Used when replaying data.
112 InputState replay_state_;
113
101 DISALLOW_COPY_AND_ASSIGN(GzipSourceStream); 114 DISALLOW_COPY_AND_ASSIGN(GzipSourceStream);
102 }; 115 };
103 116
104 } // namespace net 117 } // namespace net
105 118
106 #endif // NET_FILTER_GZIP_SOURCE_STREAM_H__ 119 #endif // NET_FILTER_GZIP_SOURCE_STREAM_H__
OLDNEW
« no previous file with comments | « no previous file | net/filter/gzip_source_stream.cc » ('j') | net/filter/gzip_source_stream.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698