rizin
rizin copied to clipboard
Fix mz header parsing issue
Your checklist for this pull request
- [x] I've read the guidelines for contributing to this repository.
- [x] I made sure to follow the project's coding style.
- [ ] I've documented every
RZ_APIfunction and struct this PR changes. - [ ] I've added tests that prove my changes are effective (required for changes to
RZ_API). - [ ] I've updated the Rizin book with the relevant information (if needed).
- [x] I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.
Detailed description
This PR fixes a bug in Rizin's DOS MZ binary format parser that prevented proper parsing of MZ files generated by Intel compilers.
Problem:
- Rizin failed to parse DOS MZ files from Intel compilers (e.g., IC96.exe)
- Files would open but fail to extract code sections, functions, and entrypoints
- Error: "The entry point is outside the load module size"
Root Causes Identified:
- Overly strict entrypoint validation - Rejected valid entrypoints outside calculated load_module_size
- Poor segment detection - Relied heavily on relocations, failing for files without them
- Rigid file size validation - Complete failure on malformed/truncated files
- Missing safety checks - Potential crashes from null pointer dereferences
Test plan
- Code compiles without errors
- Existing MZ test suite should pass
- The previously broken segments test should now work
- Intel compiler files (IC96.exe, etc.) should now be analyzable
Closing issues
Fixes #5576
Please don't remove the PR template.
Converted it to a draft for now. Please fix the tests and mark it ready for review once green.
It doesn't even compile! https://github.com/rizinorg/rizin/actions/runs/20128085000/job/57763204154?pr=5599#step:12:1974
AI slop