shepmaster / jetscii

A tiny library to efficiently search strings for sets of ASCII characters and byte slices for sets of bytes.
Apache License 2.0
113 stars 21 forks source link

Do not perform a cmpestri operation on a zero-length haystack #45

Closed martony38 closed 3 years ago

martony38 commented 3 years ago

This fixes #44.

Got some time today and was able to reproduce the segfault in the test does_not_access_memory_after_haystack_when_haystack_is_multiple_of_16_bytes_and_no_match.

If the needle was not in the haystack and the haystack was 16 bytes, the haystack pointer was reset to point at memory after the haystack which could lead to a segfault depending on the location of the memory. The fix is to return early if the haystack is empty.

shepmaster commented 3 years ago

Thanks so much for the pull request! This is one of those bugs that's totally obvious in hindsight... 😵

I realize that I've let CI infrastructure lapse on this repo, so I'm setting up GitHub Actions first, then I'll rebase this PR. The contents all look good though.

Pittsburgh, PA, USA

Hopefully I'll see you at the local Rust meetup, if Carol and I ever restart it 🤞.

shepmaster commented 3 years ago

Released in 0.5.1. Thanks again!