fix potential invalid mmap call and uninitialized file size#4559
Open
richardsonnick wants to merge 1 commit intofacebook:devfrom
Open
fix potential invalid mmap call and uninitialized file size#4559richardsonnick wants to merge 1 commit intofacebook:devfrom
richardsonnick wants to merge 1 commit intofacebook:devfrom
Conversation
Fixes a warning from Clang 21 (unix.StdCLibraryFunctions) where mmap() could be called with a length of 0 if the dictionary file is empty. Mapping a zero-length range is undefined behavior under POSIX. - Added guard for zero-length dictionary files.
terrelln
requested changes
Feb 27, 2026
Contributor
terrelln
left a comment
There was a problem hiding this comment.
One minor change, otherwise looks good. Thanks for the PR!
Comment on lines
+1054
to
+1056
| if (fileSize == (unsigned long long)-1) { | ||
| EXM_THROW(35, "Could not determine size of dictionary %s", fileName); | ||
| } |
Contributor
There was a problem hiding this comment.
Can you move this check up to just after line 1044, because the flow should never reach here, due to the check on 1046.
And please also check against UTIL_FILESIZE_UNKNOWN rather than -1.
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.
Fixes a warning from Clang 21 (unix.StdCLibraryFunctions) where mmap() could be called with a length of 0 if the dictionary file is empty. Mapping a zero-length range is undefined behavior under POSIX.
Reported-by: Clang 21 Static Analyzer