Skip to content

Commit

Permalink
Be strict about maxPayloadLength in inflate
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Jan 1, 2020
1 parent 6fe5ea4 commit bbbe3bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fuzzing/PerMessageDeflate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
std::string_view inflation = staticData.inflationStream.inflate(&staticData.zlibContext, std::string_view((char *) data, size), 256);
if (inflation.length() > 256) {
/* Cause ASAN to freak out */
//delete (int *) (void *) 1;
delete (int *) (void *) 1;
}
});

Expand Down
11 changes: 11 additions & 0 deletions src/PerMessageDeflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,20 @@ struct InflationStream {

if (zlibContext->dynamicInflationBuffer.length()) {
zlibContext->dynamicInflationBuffer.append(zlibContext->inflationBuffer, LARGE_BUFFER_SIZE - inflationStream.avail_out);

/* Let's be strict about the max size */
if (zlibContext->dynamicInflationBuffer.length() > maxPayloadLength) {
return {nullptr, 0};
}

return {zlibContext->dynamicInflationBuffer.data(), zlibContext->dynamicInflationBuffer.length()};
}

/* Let's be strict about the max size */
if ((LARGE_BUFFER_SIZE - inflationStream.avail_out) > maxPayloadLength) {
return {nullptr, 0};
}

return {zlibContext->inflationBuffer, LARGE_BUFFER_SIZE - inflationStream.avail_out};
}

Expand Down

0 comments on commit bbbe3bd

Please sign in to comment.