Skip to content

fix potential invalid mmap call and uninitialized file size#4559

Open
richardsonnick wants to merge 1 commit intofacebook:devfrom
richardsonnick:fix-zero-filesize-mmap
Open

fix potential invalid mmap call and uninitialized file size#4559
richardsonnick wants to merge 1 commit intofacebook:devfrom
richardsonnick:fix-zero-filesize-mmap

Conversation

@richardsonnick
Copy link
Contributor

@richardsonnick richardsonnick commented Dec 23, 2025

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.

Reported-by: Clang 21 Static Analyzer

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.
@meta-cla meta-cla bot added the CLA Signed label Dec 23, 2025
Copy link
Contributor

@terrelln terrelln left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants