Deprecate SDCH-related net::SourceStream types
- Deprecated three SDCH-related net::SourceStream types - Modify URLRequestHttpJob::SetUpSourceStream() to not include default case Bug: 764434, 764433, 762686 Change-Id: I93320bfee930484da76a0a29fab2224f2b886523 Reviewed-on: https://chromium-review.googlesource.com/667731 Commit-Queue: Helen Li <xunjieli@chromium.org> Reviewed-by: Randy Smith <rdsmith@chromium.org> Cr-Commit-Position: refs/heads/master@{#502337}
This commit is contained in:
@ -19,7 +19,6 @@ namespace {
|
||||
|
||||
const char kDeflate[] = "deflate";
|
||||
const char kGZip[] = "gzip";
|
||||
const char kSdch[] = "sdch";
|
||||
const char kXGZip[] = "x-gzip";
|
||||
const char kBrotli[] = "br";
|
||||
|
||||
@ -84,8 +83,6 @@ FilterSourceStream::SourceType FilterSourceStream::ParseEncodingType(
|
||||
} else if (base::LowerCaseEqualsASCII(encoding, kGZip) ||
|
||||
base::LowerCaseEqualsASCII(encoding, kXGZip)) {
|
||||
return TYPE_GZIP;
|
||||
} else if (base::LowerCaseEqualsASCII(encoding, kSdch)) {
|
||||
return TYPE_SDCH;
|
||||
} else {
|
||||
return TYPE_UNKNOWN;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ namespace {
|
||||
|
||||
const char kDeflate[] = "DEFLATE";
|
||||
const char kGzip[] = "GZIP";
|
||||
const char kGzipFallback[] = "GZIP_FALLBACK";
|
||||
|
||||
// For deflate streams, if more than this many bytes have been received without
|
||||
// an error and without adding a Zlib header, assume the original stream had a
|
||||
@ -40,6 +39,7 @@ GzipSourceStream::~GzipSourceStream() {
|
||||
std::unique_ptr<GzipSourceStream> GzipSourceStream::Create(
|
||||
std::unique_ptr<SourceStream> upstream,
|
||||
SourceStream::SourceType type) {
|
||||
DCHECK(type == TYPE_GZIP || type == TYPE_DEFLATE);
|
||||
std::unique_ptr<GzipSourceStream> source(
|
||||
new GzipSourceStream(std::move(upstream), type));
|
||||
|
||||
@ -62,7 +62,7 @@ bool GzipSourceStream::Init() {
|
||||
memset(zlib_stream_.get(), 0, sizeof(z_stream));
|
||||
|
||||
int ret;
|
||||
if (type() == TYPE_GZIP || type() == TYPE_GZIP_FALLBACK) {
|
||||
if (type() == TYPE_GZIP) {
|
||||
ret = inflateInit2(zlib_stream_.get(), -MAX_WBITS);
|
||||
} else {
|
||||
ret = inflateInit(zlib_stream_.get());
|
||||
@ -75,8 +75,6 @@ std::string GzipSourceStream::GetTypeAsString() const {
|
||||
switch (type()) {
|
||||
case TYPE_GZIP:
|
||||
return kGzip;
|
||||
case TYPE_GZIP_FALLBACK:
|
||||
return kGzipFallback;
|
||||
case TYPE_DEFLATE:
|
||||
return kDeflate;
|
||||
default:
|
||||
@ -104,14 +102,8 @@ int GzipSourceStream::FilterData(IOBuffer* output_buffer,
|
||||
input_state_ = STATE_SNIFFING_DEFLATE_HEADER;
|
||||
break;
|
||||
}
|
||||
// If this stream is not really gzipped as detected by
|
||||
// ShouldFallbackToPlain, pretend that the zlib stream has ended.
|
||||
DCHECK_LT(0, input_data_size);
|
||||
if (ShouldFallbackToPlain(input_data[0])) {
|
||||
input_state_ = STATE_UNCOMPRESSED_BODY;
|
||||
} else {
|
||||
input_state_ = STATE_GZIP_HEADER;
|
||||
}
|
||||
input_state_ = STATE_GZIP_HEADER;
|
||||
break;
|
||||
}
|
||||
case STATE_GZIP_HEADER: {
|
||||
@ -276,14 +268,4 @@ bool GzipSourceStream::InsertZlibHeader() {
|
||||
return ret == Z_OK;
|
||||
}
|
||||
|
||||
// Dumb heuristic. Gzip files always start with a two-byte magic value per RFC
|
||||
// 1952 2.3.1, so if the first byte isn't the first byte of the gzip magic, and
|
||||
// this filter is checking whether it should fallback, then fallback.
|
||||
bool GzipSourceStream::ShouldFallbackToPlain(char first_byte) {
|
||||
if (type() != TYPE_GZIP_FALLBACK)
|
||||
return false;
|
||||
static const char kGzipFirstByte = 0x1f;
|
||||
return first_byte != kGzipFirstByte;
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
|
@ -82,11 +82,6 @@ class NET_EXPORT_PRIVATE GzipSourceStream : public FilterSourceStream {
|
||||
// success.
|
||||
bool InsertZlibHeader();
|
||||
|
||||
// Returns whether this stream looks like it could be plain text (ie, not
|
||||
// actually gzipped). Right now this uses an extremely simple heuristic; see
|
||||
// the source for details. This method checks the first byte of the stream.
|
||||
bool ShouldFallbackToPlain(char first_byte);
|
||||
|
||||
// The control block of zlib which actually does the decoding.
|
||||
// This data structure is initialized by Init and updated only by
|
||||
// FilterData(), with InsertZlibHeader() being the exception as a workaround.
|
||||
|
@ -21,8 +21,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
new net::FuzzedSourceStream(&data_provider));
|
||||
|
||||
const net::SourceStream::SourceType kGzipTypes[] = {
|
||||
net::SourceStream::TYPE_GZIP, net::SourceStream::TYPE_DEFLATE,
|
||||
net::SourceStream::TYPE_GZIP_FALLBACK};
|
||||
net::SourceStream::TYPE_GZIP, net::SourceStream::TYPE_DEFLATE};
|
||||
net::SourceStream::SourceType type =
|
||||
data_provider.PickValueInArray(kGzipTypes);
|
||||
std::unique_ptr<net::GzipSourceStream> gzip_stream =
|
||||
|
@ -60,11 +60,10 @@ class GzipSourceStreamTest : public ::testing::TestWithParam<GzipTestParam> {
|
||||
GzipSourceStreamTest() : output_buffer_size_(GetParam().buffer_size) {}
|
||||
|
||||
// Helpful function to initialize the test fixture.|type| specifies which type
|
||||
// of GzipSourceStream to create. It must be one of TYPE_GZIP,
|
||||
// TYPE_GZIP_FALLBACK and TYPE_DEFLATE.
|
||||
// of GzipSourceStream to create. It must be one of TYPE_GZIP and
|
||||
// TYPE_DEFLATE.
|
||||
void Init(SourceStream::SourceType type) {
|
||||
EXPECT_TRUE(SourceStream::TYPE_GZIP == type ||
|
||||
SourceStream::TYPE_GZIP_FALLBACK == type ||
|
||||
SourceStream::TYPE_DEFLATE == type);
|
||||
source_data_len_ = kBigBufferSize - kEOFMargin;
|
||||
|
||||
@ -272,19 +271,6 @@ TEST_P(GzipSourceStreamTest, CorruptGzipHeader) {
|
||||
EXPECT_EQ("GZIP", stream()->Description());
|
||||
}
|
||||
|
||||
TEST_P(GzipSourceStreamTest, GzipFallback) {
|
||||
Init(SourceStream::TYPE_GZIP_FALLBACK);
|
||||
source()->AddReadResult(source_data(), source_data_len(), OK,
|
||||
GetParam().mode);
|
||||
source()->AddReadResult(nullptr, 0, OK, GetParam().mode);
|
||||
|
||||
std::string actual_output;
|
||||
int rv = ReadStream(&actual_output);
|
||||
EXPECT_EQ(static_cast<int>(source_data_len()), rv);
|
||||
EXPECT_EQ(std::string(source_data(), source_data_len()), actual_output);
|
||||
EXPECT_EQ("GZIP_FALLBACK", stream()->Description());
|
||||
}
|
||||
|
||||
// This test checks that the gzip stream source works correctly on 'golden' data
|
||||
// as produced by gzip(1).
|
||||
TEST_P(GzipSourceStreamTest, GzipCorrectness) {
|
||||
|
@ -7,9 +7,9 @@
|
||||
SOURCE_STREAM_TYPE(BROTLI)
|
||||
SOURCE_STREAM_TYPE(DEFLATE)
|
||||
SOURCE_STREAM_TYPE(GZIP)
|
||||
SOURCE_STREAM_TYPE(GZIP_FALLBACK)
|
||||
SOURCE_STREAM_TYPE(SDCH)
|
||||
SOURCE_STREAM_TYPE(SDCH_POSSIBLE)
|
||||
SOURCE_STREAM_TYPE(GZIP_FALLBACK_DEPRECATED)
|
||||
SOURCE_STREAM_TYPE(SDCH_DEPRECATED)
|
||||
SOURCE_STREAM_TYPE(SDCH_POSSIBLE_DEPRECATED)
|
||||
SOURCE_STREAM_TYPE(INVALID)
|
||||
SOURCE_STREAM_TYPE(NONE)
|
||||
SOURCE_STREAM_TYPE(REJECTED)
|
||||
|
@ -1013,15 +1013,21 @@ std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() {
|
||||
case SourceStream::TYPE_NONE:
|
||||
// Identity encoding type. Pass through raw response body.
|
||||
return upstream;
|
||||
case SourceStream::TYPE_SDCH:
|
||||
// Pass through raw sdch response.
|
||||
default:
|
||||
case SourceStream::TYPE_UNKNOWN:
|
||||
// Unknown encoding type. Pass through raw response body.
|
||||
// Despite of reporting to UMA, request will not be canceled; though
|
||||
// it is expected that user will see malformed / garbage response.
|
||||
FilterSourceStream::ReportContentDecodingFailed(
|
||||
FilterSourceStream::TYPE_UNKNOWN);
|
||||
return upstream;
|
||||
case SourceStream::TYPE_GZIP_FALLBACK_DEPRECATED:
|
||||
case SourceStream::TYPE_SDCH_DEPRECATED:
|
||||
case SourceStream::TYPE_SDCH_POSSIBLE_DEPRECATED:
|
||||
case SourceStream::TYPE_REJECTED:
|
||||
case SourceStream::TYPE_INVALID:
|
||||
case SourceStream::TYPE_MAX:
|
||||
NOTREACHED();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1036,11 +1042,11 @@ std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() {
|
||||
break;
|
||||
case SourceStream::TYPE_GZIP:
|
||||
case SourceStream::TYPE_DEFLATE:
|
||||
case SourceStream::TYPE_GZIP_FALLBACK:
|
||||
downstream = GzipSourceStream::Create(std::move(upstream), type);
|
||||
break;
|
||||
case SourceStream::TYPE_SDCH:
|
||||
case SourceStream::TYPE_SDCH_POSSIBLE:
|
||||
case SourceStream::TYPE_GZIP_FALLBACK_DEPRECATED:
|
||||
case SourceStream::TYPE_SDCH_DEPRECATED:
|
||||
case SourceStream::TYPE_SDCH_POSSIBLE_DEPRECATED:
|
||||
case SourceStream::TYPE_NONE:
|
||||
case SourceStream::TYPE_INVALID:
|
||||
case SourceStream::TYPE_REJECTED:
|
||||
|
@ -178,29 +178,6 @@ TEST_F(URLRequestHttpJobSetUpSourceTest, UnknownEncoding) {
|
||||
EXPECT_EQ("Test Content", delegate_.data_received());
|
||||
}
|
||||
|
||||
// Received a SDCH encoded response when Sdch is not advertised.
|
||||
TEST_F(URLRequestHttpJobSetUpSourceTest, SdchNotAdvertisedGotSdchResponse) {
|
||||
MockWrite writes[] = {MockWrite(kSimpleGetMockWrite)};
|
||||
MockRead reads[] = {MockRead("HTTP/1.1 200 OK\r\n"
|
||||
"Content-Encoding: sdch\r\n"
|
||||
"Content-Length: 12\r\n\r\n"),
|
||||
MockRead("Test Content")};
|
||||
|
||||
StaticSocketDataProvider socket_data(reads, arraysize(reads), writes,
|
||||
arraysize(writes));
|
||||
socket_factory_.AddSocketDataProvider(&socket_data);
|
||||
|
||||
std::unique_ptr<URLRequest> request =
|
||||
context_.CreateRequest(GURL("http://www.example.com"), DEFAULT_PRIORITY,
|
||||
&delegate_, TRAFFIC_ANNOTATION_FOR_TESTS);
|
||||
auto job = std::make_unique<TestURLRequestHttpJob>(request.get());
|
||||
test_job_interceptor_->set_main_intercept_job(std::move(job));
|
||||
request->Start();
|
||||
|
||||
base::RunLoop().Run();
|
||||
EXPECT_EQ(ERR_CONTENT_DECODING_FAILED, delegate_.request_status());
|
||||
}
|
||||
|
||||
class URLRequestHttpJobTest : public ::testing::Test {
|
||||
protected:
|
||||
URLRequestHttpJobTest() : context_(true) {
|
||||
|
Reference in New Issue
Block a user