Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reader::open_mmap is unsound because it allows the caller to violate MmapOptions::map invariants #86

Open
paolobarbolini opened this issue Jan 8, 2025 · 0 comments

Comments

@paolobarbolini
Copy link

The Reader::open_mmap function is declared as a safe function that internally opens a file and calls MmapOptions::new().map(&file). The docs for MmapOptions say:

All file-backed memory map constructors are marked unsafe because of the potential for Undefined Behavior (UB) using the map if the underlying file is subsequently modified, in or out of process. Applications must consider the risk and take appropriate precautions when using file-backed maps. Solutions such as file permissions, locks or process-private (e.g. unlinked) files exist but are platform specific and limited.

maxminddb makes no effort in preventing the file from being modified from under it, leading to Reader::open_mmap being unsound. For the implementation to be sound the function must either be unsafe and require the user verify that their code abides by the memmap2 invariants, or effort to lock the file and make it read-only must be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant