Port changes to the extract() function from the skey patchset, fixing an out-of-bounds read. Fix signedness of first function argument.
Fix the extract() function not to access unnecessary array elements; this avoids an out-of-bounds read when called from btoe() or etob(). Change the insert() function to use similar logic as extract(). Bug: 567608