{{ message }}
Repository navigation
ICU-23078 Use CharString for file names in genrb parseTransliterator and parseDependency - #4258
Open
ManoharPaturi wants to merge 1 commit into
Open
ManoharPaturi wants to merge 1 commit into
ManoharPaturi wants to merge 1 commit into
Conversation
…and parseDependency parseTransliterator and parseDependency assembled file names in fixed size stack buffers with unchecked concatenation: the resource string token was copied into a 128 byte buffer and the input or output directory and the token were appended to a 256 byte buffer. A bundle with a long file name token, or a deep enough directory, overran the buffers, which shows up as random genrb crashes in build systems with long paths. Build the file names with CharString, as parseUCARules already does, so the buffers grow as needed and non invariant characters are reported instead of being copied. Add a genrb regression test that runs the tool on bundles with overlong transliterator and dependency file names.
Author
This branch has not been deployed
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.

Description
ICU-23078 reports stack buffer overflows in genrb when building data from a deep enough directory. Following the report, I reproduced and fixed the two remaining fixed size file name buffers in
parse.cpp.parseTransliteratorandparseDependencyboth declared:and filled them with unchecked
uprv_strcatcalls: the input or output directory first, thenu_UCharsToChars(tokenValue->fChars, cs, tokenValue->fLength)which copies the resource string token of any length into the 128 byte buffer.A bundle source with a 200 character file name in a
process(transliterator)resource, run against a genrb built with address sanitizer:The same report appears for
parseDependencywith aprocess(dependency)resource. Beyond the long token, the directory concatenation overflowsfilename[256]when the configured input or output directory is long, which matches the random build system crashes from the ticket.The fix builds the file names with
CharString, the same approachparseUCARulesin the same file already uses, so the buffer grows as needed and non invariant characters in the token are reported as an error rather than copied. With this change the reproducer bundles produce a clean file open error for the transliterator case and a clean warning for the dependency case.parseUCARuleswas already converted toCharString, so this closes the remaining two functions named in the ticket.Testing
Added
genrb_test.py, wired intocheck-localof the genrb Makefile following the pattern of the makeconv tool test. The test writes a valid transliterator bundle and bundles with 300 character file names in bothprocess(transliterator)andprocess(dependency)resources, and checks that genrb accepts the first and last with a written.resfile and reports a clean error for the unopenable transliterator file. Run against the pre-fix genrb the test fails with the sanitizer abort; against the fixed genrb it passes.The full ICU data, including
translit/root.txtwhich usesprocess(transliterator), rebuilds with the changed genrb, andintltest translitpasses.ICU-23078
Checklist