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

Unsound usages of unsafe implementation from smaller size to larger size #164

Closed llooFlashooll closed 4 months ago

llooFlashooll commented 4 months ago

Hi, I am scanning the httparse in the latest version with my own static analyzer tool.

Unsafe conversion found at: src/simd/sse42.rs:57:32: 57:47

let data = _mm_lddqu_si128(ptr as *const _);

This unsound implementation would create a misalignment issues. If the [u8] size is smaller than the i128, it would potentially lead to access out-of-bound in the memory.

This would potentially cause undefined behaviors in Rust. If we further manipulate the problematic converted types, it would potentially lead to different consequences. I am reporting this issue for your attention.

seanmonstar commented 4 months ago

Can you say more about what specifically is the issue? There's an assert at the beginning of the function that there are at least 16 bytes in the slice. And the place this function is called, the function above it, also checks there are at least 16 bytes.

llooFlashooll commented 4 months ago

I see, thanks for your reply. If there're assertions, there may not be any issue here.