Fix out-of-bounds reads in Arabic shaping space handling#4043
Open
ubeddulla wants to merge 1 commit into
Open
Conversation
handleGeneratedSpaces started its begin-spacing loop at index sourceLength and expandCompositCharAtNear read dest[i+1] without a range check, so both touched one element past the sourceLength-sized scratch buffer that u_shapeArabic allocates. Start the loop at sourceLength-1 like its sibling and guard the lamalef lookahead with (i < sourceLength-1) as the nearby code already does.
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
handleGeneratedSpacesandexpandCompositCharAtNearinushape.cppwalk the shaping scratch buffer one element past its end: the begin-spacing loop starts its index atsourceLengthso it readsdest[sourceLength], and the near lamalef expansion readsdest[i+1]without checkingi+1is still in range.u_shapeArabichands these helpers a buffer of exactlysourceLengthUChars, heap-allocated once the input passes the 300-element stack fallback, soU_SHAPE_LAMALEF_BEGIN,U_SHAPE_TASHKEEL_BEGINandU_SHAPE_LETTERS_UNSHAPE | U_SHAPE_LAMALEF_NEARread out of bounds on a ~400-char input, which AddressSanitizer reports atushape.cpp:828. The begin loop now starts atsourceLength-1like its sibling at line 929, and the lamalef lookahead is guarded with(i < sourceLength-1)the way the nearby code at line 1396 already does. The new cintltst case fails under asan before the change and passes after, and the existing shaping output is unchanged.Checklist