mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:57:41 +00:00
LibHTTP: Handle chunk sizes that start with zeros correctly
Apparently that's allowed and the RFC is just unclear about it. Some servers seem to zero-pad the chunk size for whatever reason, and previously, we interpreted that as the last chunk.
This commit is contained in:
parent
7d76299ca9
commit
50c0944767
1 changed files with 13 additions and 9 deletions
|
@ -163,13 +163,24 @@ void Job::on_socket_connected()
|
||||||
// read size
|
// read size
|
||||||
auto size_data = read_line(PAGE_SIZE);
|
auto size_data = read_line(PAGE_SIZE);
|
||||||
auto size_lines = StringView { size_data.data(), size_data.size() }.lines();
|
auto size_lines = StringView { size_data.data(), size_data.size() }.lines();
|
||||||
|
#ifdef JOB_DEBUG
|
||||||
|
dbg() << "Job: Received a chunk with size _" << size_data << "_";
|
||||||
|
#endif
|
||||||
if (size_lines.size() == 0) {
|
if (size_lines.size() == 0) {
|
||||||
dbg() << "Job: Reached end of stream";
|
dbg() << "Job: Reached end of stream";
|
||||||
m_state = State::AfterChunkedEncodingTrailer;
|
m_state = State::AfterChunkedEncodingTrailer;
|
||||||
return IterationDecision::Break;
|
return IterationDecision::Break;
|
||||||
} else {
|
} else {
|
||||||
String size_string = size_lines[0];
|
auto chunk = size_lines[0].split_view(';', true);
|
||||||
if (size_string.starts_with('0')) {
|
String size_string = chunk[0];
|
||||||
|
char* endptr;
|
||||||
|
auto size = strtoul(size_string.characters(), &endptr, 16);
|
||||||
|
if (*endptr) {
|
||||||
|
// invalid number
|
||||||
|
deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::TransmissionFailed); });
|
||||||
|
return IterationDecision::Break;
|
||||||
|
}
|
||||||
|
if (size == 0) {
|
||||||
// This is the last chunk
|
// This is the last chunk
|
||||||
// '0' *[; chunk-ext-name = chunk-ext-value]
|
// '0' *[; chunk-ext-name = chunk-ext-value]
|
||||||
// We're going to ignore _all_ chunk extensions
|
// We're going to ignore _all_ chunk extensions
|
||||||
|
@ -180,13 +191,6 @@ void Job::on_socket_connected()
|
||||||
dbg() << "Job: Received the last chunk with extensions _" << size_string.substring_view(1, size_string.length() - 1) << "_";
|
dbg() << "Job: Received the last chunk with extensions _" << size_string.substring_view(1, size_string.length() - 1) << "_";
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
char* endptr;
|
|
||||||
auto size = strtoul(size_string.characters(), &endptr, 16);
|
|
||||||
if (*endptr) {
|
|
||||||
// invalid number
|
|
||||||
deferred_invoke([this](auto&) { did_fail(Core::NetworkJob::Error::TransmissionFailed); });
|
|
||||||
return IterationDecision::Break;
|
|
||||||
}
|
|
||||||
m_current_chunk_total_size = size;
|
m_current_chunk_total_size = size;
|
||||||
m_current_chunk_remaining_size = size;
|
m_current_chunk_remaining_size = size;
|
||||||
read_size = size;
|
read_size = size;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue