Fix SIGSEGV in StringPiece::find_first_of
authorMike Curtiss <mcurtiss@fb.com>
Tue, 12 Feb 2013 22:39:13 +0000 (14:39 -0800)
committerJordan DeLong <jdelong@fb.com>
Tue, 19 Mar 2013 00:07:36 +0000 (17:07 -0700)
commit4f7a54f61beb30942dc69ced22c776d2dd84e3d2
tree02486e1e6d16c58038c9baec7f693150e7632700
parenta8b4b5ea1e090f4dff374aec509119e842297956
Fix SIGSEGV in StringPiece::find_first_of

Summary:
Our SSE version of find_first_of was reading past the end of
the StringPiece in some cases, which (very rarely) caused a seg-fault
when we were reading outside of our allotted virtual address space.

Modify the code to never read past the end of the underlying buffers
except when we think it's "safe" because we're still within the same
page. (ASSUMPTION: if a process is allowed to read a byte within a
page, then it is allowed to read _all_ bytes within that page.)

Test Plan:
Added tests that verify we won't go across page boundaries.

Sadly, this code hurts our benchmarks -- sometimes by up to 50% for
smaller strings.

Reviewed By: philipp@fb.com

FB internal diff: D707923

Blame Revision: D638500
folly/Range.cpp
folly/test/RangeTest.cpp