seanmonstar / httparse

A push parser for the HTTP 1.x protocol in Rust.
https://docs.rs/httparse
Apache License 2.0
584 stars 114 forks source link

Fix SIMD header value check on char >= 0x80 #106

Closed eaufavor closed 2 years ago

eaufavor commented 2 years ago

The SIMD intrinsics *_cmpgt_epi8 are for signed chars. This change correctly performs the unsigned comparison.

nox commented 2 years ago

Could you describe the problem a bit more? Why does it matter that the intrinsics are for signed chars? Is there a bug in current httparse?

eaufavor commented 2 years ago

The intention of the code is to check if the char is greater than 0x1f. However for a char >= 0x80, *_cmpgt_epi8 treats it as negative number. So all the chars that >= 0x80 are treated as if they are <= 0x1f, which will make them to be rejected as illegal header values.