Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/protocol/http1/body/chunked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def read
connection.close_read
end

raise EOFError, "Connection closed before expected length was read!"
raise
end

# @returns [String] a human-readable representation of the body.
Expand All @@ -149,7 +149,7 @@ def as_json(...)

# Read the trailer from the connection, and add any headers to the trailer.
def read_trailer
while line = @connection.read_line?
while line = @connection.read_line
# Empty line indicates end of trailer:
break if line.empty?

Expand Down
4 changes: 4 additions & 0 deletions releases.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Releases

## Unreleased

- Handle unexpected EOF while reading chunked trailers.

## v0.40.1

- Bound fixed-length and chunked body reads, and validate chunk terminators.
Expand Down
10 changes: 10 additions & 0 deletions test/protocol/http1/body/chunked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@
end
end

with "incomplete trailer" do
let(:buffer) {StringIO.new("0\r\n")}

it "raises EOFError when the final CRLF is missing" do
expect{body.read}.to raise_exception(EOFError)

expect(connection).to be(:half_closed_remote?)
end
end

with "bad trailers" do
let(:postfix) {":ETag abcd\r\n"}

Expand Down
Loading