|
@@ -4187,6 +4187,11 @@ public:
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
bool is_valid_ = false;
|
|
bool is_valid_ = false;
|
|
|
|
|
+ // RFC 1952 2.2: a gzip body is a series of members. Once one ends, the bytes
|
|
|
|
|
+ // after it either start another one or are ignored.
|
|
|
|
|
+ bool member_ended_ = false;
|
|
|
|
|
+ bool ignore_rest_ = false;
|
|
|
|
|
+ size_t next_id_bytes_ = 0; // bytes of the next member's ID1 ID2 seen so far
|
|
|
z_stream strm_;
|
|
z_stream strm_;
|
|
|
};
|
|
};
|
|
|
#endif
|
|
#endif
|
|
@@ -8889,6 +8894,8 @@ inline bool gzip_decompressor::decompress(const char *data, size_t data_length,
|
|
|
Callback callback) {
|
|
Callback callback) {
|
|
|
assert(is_valid_);
|
|
assert(is_valid_);
|
|
|
|
|
|
|
|
|
|
+ if (ignore_rest_) { return true; }
|
|
|
|
|
+
|
|
|
auto ret = Z_OK;
|
|
auto ret = Z_OK;
|
|
|
|
|
|
|
|
do {
|
|
do {
|
|
@@ -8907,6 +8914,38 @@ inline bool gzip_decompressor::decompress(const char *data, size_t data_length,
|
|
|
strm_.avail_out = static_cast<uInt>(buff.size());
|
|
strm_.avail_out = static_cast<uInt>(buff.size());
|
|
|
strm_.next_out = reinterpret_cast<Bytef *>(buff.data());
|
|
strm_.next_out = reinterpret_cast<Bytef *>(buff.data());
|
|
|
|
|
|
|
|
|
|
+ if (member_ended_) {
|
|
|
|
|
+ // Another member starts with ID1 ID2, which may come split across
|
|
|
|
|
+ // calls. Anything else after a member is ignored, as it always was.
|
|
|
|
|
+ static const Bytef id[] = {0x1f, 0x8b};
|
|
|
|
|
+ while (next_id_bytes_ < sizeof(id) && strm_.avail_in > 0) {
|
|
|
|
|
+ if (*strm_.next_in != id[next_id_bytes_]) {
|
|
|
|
|
+ ignore_rest_ = true;
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+ next_id_bytes_++;
|
|
|
|
|
+ strm_.next_in++;
|
|
|
|
|
+ strm_.avail_in--;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (next_id_bytes_ < sizeof(id) || strm_.avail_in == 0) { continue; }
|
|
|
|
|
+
|
|
|
|
|
+ // Hand the ID bytes taken above to inflate before the rest
|
|
|
|
|
+ inflateReset(&strm_);
|
|
|
|
|
+ auto next_in = strm_.next_in;
|
|
|
|
|
+ auto avail_in = strm_.avail_in;
|
|
|
|
|
+ strm_.next_in = const_cast<Bytef *>(id);
|
|
|
|
|
+ strm_.avail_in = sizeof(id);
|
|
|
|
|
+ ret = inflate(&strm_, Z_NO_FLUSH);
|
|
|
|
|
+ strm_.next_in = next_in;
|
|
|
|
|
+ strm_.avail_in = avail_in;
|
|
|
|
|
+ member_ended_ = false;
|
|
|
|
|
+ next_id_bytes_ = 0;
|
|
|
|
|
+ if (ret != Z_OK) {
|
|
|
|
|
+ inflateEnd(&strm_);
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
ret = inflate(&strm_, Z_NO_FLUSH);
|
|
ret = inflate(&strm_, Z_NO_FLUSH);
|
|
|
|
|
|
|
|
assert(ret != Z_STREAM_ERROR);
|
|
assert(ret != Z_STREAM_ERROR);
|
|
@@ -8919,6 +8958,11 @@ inline bool gzip_decompressor::decompress(const char *data, size_t data_length,
|
|
|
if (!callback(buff.data(), buff.size() - strm_.avail_out)) {
|
|
if (!callback(buff.data(), buff.size() - strm_.avail_out)) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (ret == Z_STREAM_END) {
|
|
|
|
|
+ member_ended_ = true;
|
|
|
|
|
+ ret = Z_OK;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (ret != Z_OK && ret != Z_STREAM_END) { return false; }
|
|
if (ret != Z_OK && ret != Z_STREAM_END) { return false; }
|