fix(commons): handle VLM raw-image allocation and size failures - #814
sanchitmonga22 merged 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe adapter adds overflow-safe image-size checks, validates RGB and RGBA payloads and allocations, and maps supported embedding input types from protobuf values. ChangesAdapter conversion validation
Estimated code review effort: 2 (Simple) | ~15 minutes Merge Risk: ⚪ Minimal · up to Raw image conversion now rejects invalid dimensions, malformed payload sizes, overflowed allocations, and unsupported embedding input types before publishing output buffers. No current merge-blocking risk is identified. Suggested reviewers: 🚥 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 |
sanchitmonga22
left a comment
There was a problem hiding this comment.
Thanks a lot for this, @shubhamsinnh! This closes a heap over-read/overflow in the VLM raw_rgb/raw_rgba proto adapter -- a malformed image with dimensions larger than (or overflowing against) the payload could over-read the heap, and a failed allocation could get written through silently.
Checked: CodeRabbit reviewed the latest commit · CI green · built and linted locally merged into main (core-cpp-commons) · two independent code reviews.
Follow-ups, not blocking: #893 (validating raw image size in the direct C-struct VLM entry points too), #894 (surfacing a specific error when raw image validation fails), #895 (test coverage for the new raw_rgb/raw_rgba checks) -- you're welcome to pick these up.
Merging now -- really appreciate the contribution!
Reviewed with help from Claude Code and Codex.
Description
Commons converted raw VLM image payloads without fully validating their dimensions or allocation results. Raw RGB copied through an unchecked allocation, while RGBA conversion multiplied width, height, and channel counts without guarding
size_toverflow before writing the output buffer. On constrained builds, particularly 32-bit WASM, malformed or oversized dimensions could therefore produce an undersized allocation or a null-pointer write.Validate positive dimensions and every byte-count multiplication before allocating. Require tightly packed RGB/RGBA payloads to exactly match their declared dimensions, return conversion failure when allocation fails, and publish the converted pixel buffer only after the copy or conversion succeeds.
The change stays at the shared Commons proto boundary and does not alter the public C ABI or protobuf schema.
Type of Change
Testing
git diff --checkrac_proto_adapters.cppcompiled successfully to an object with GCC 16 and C++20SortIncludes: CaseSensitiveconfigurationChecklist
Screenshots
Not applicable; no UI changes.
Summary by CodeRabbit