Repository navigation
Fix heap-buffer-overflow reading MD2 skin names - #6832
Conversation
The skin name field in an MD2 file is a fixed 64-byte buffer copied straight from the file, with nothing guaranteeing it actually contains a NUL terminator. If a malformed or crafted file fills those 64 bytes with non-zero data right up against the end of the file, strlen() on that field walks straight past the end of the read buffer looking for a terminator that isn't there. Bounded the scan with strnlen() capped at one less than the field's size instead, the same approach MDCLoader already uses for its own fixed-size name fields. Added a regression test with a hand-built MD2 file that reproduces the crash under ASan on the old code and imports cleanly with the fix.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe MD2 loader now bounds skin-name scanning with ChangesMD2 skin-name safety
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The MD2 importer now bounds malformed skin-name parsing and includes regression coverage for unterminated fixed-width names. No remaining merge-blocking risk is identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
Merged, thank you for your contribution. |



The skin name in an MD2 file lives in a fixed 64-byte field copied directly out of the file, and nothing guarantees it actually has a NUL terminator anywhere inside it. On a malformed file where that field is filled with non-zero bytes right up to the end of the file,
strlen()onpcSkins->namejust keeps going past the end of the read buffer looking for a byte that isn't there.Fixed it by bounding the scan with
strnlen(), capped at one less than the field's own size.MDCLoaderalready does the same thing for its own fixed-size name fields (ucName), so this brings MD2 in line with that.Added a regression test with a small hand-built MD2 file: one skin, name field packed entirely with non-NUL bytes, ending exactly at the file's last byte. Confirmed with an ASan build that this crashes with a heap-buffer-overflow in
strlenon unmodified master, and imports cleanly with the fix applied. Full unit suite (666 tests) passes clean under ASan+UBSan.Summary by CodeRabbit
Bug Fixes
Tests