Skip to content

Commit

Permalink
fix overflow if more data on stream than content-length indicates
Browse files Browse the repository at this point in the history
  • Loading branch information
karlseguin committed Sep 22, 2024
1 parent ffdce2e commit da9e944
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ pub const State = struct {
self.pos = len;
return true;
}
if (read > cl) {
return error.InvalidContentLength;
}

// how much of the body are we missing
const missing = cl - read;
Expand Down Expand Up @@ -1203,6 +1206,11 @@ test "request: query & body" {
try t.expectString("keemun tea", (try r.query()).get("search").?);
}

test "request: invalid content-length" {
defer t.reset();
try expectParseError(error.InvalidContentLength, "GET / HTTP/1.0\r\nContent-Length: 1\r\n\r\nabc", .{ });
}

test "body: json" {
defer t.reset();
const Tea = struct {
Expand Down

0 comments on commit da9e944

Please sign in to comment.