tmm1/http_parser.rb — Issue #17: 'offset' returned by 'parser#<<' sometimes off by one?
Author: jordansissel
Created: 2012-03-04 07:34:42+00:00
State: open

Full code to reproduce this bug(?) here:

https://github.com/jordansissel/experiments/tree/master/ruby/http_parser#readme

I've copied part of the readme from above, here:

% grep failures output/*
output/jruby-1.6.6@1.8.7:2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
output/jruby-1.6.6@1.9.2:2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
output/ruby@1.8.7:2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
output/ruby@1.9.2:2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
output/ruby@1.9.3:2 tests, 2 assertions, 1 failures, 0 errors, 0 skips

This request parses properly:

request = buildrequest([
"GET /foo HTTP/1.1",
"host: localhost",
""
])

This request does not:

request = buildrequest([
"GET /websocket HTTP/1.1",
"host: localhost",
"connection: Upgrade",
"upgrade: websocket",
"sec-websocket-key: SD6/hpYbKjQ6Sown7pBbWQ==",
"sec-websocket-version: 13",
""
])

The failure is that `parser << data` is returning an offset that is one byte
short:

% grep OFFSET output/*
output/ruby@1.8.7:OFFSET WRONG? Data remaining: "\n"
output/ruby@1.9.2:.OFFSET WRONG? Data remaining: "\n"
output/ruby@1.9.3:OFFSET WRONG? Data remaining: "\n"