Skip to content

Validate raw image size in direct C-struct VLM entry points #893

Description

@sanchitmonga22

Follow-up from #814 by @shubhamsinnh -- thanks again for that PR!

What

#814 added an exact-size check (width*height*channels == data_size) for VLM images that arrive through the protobuf adapter (core/src/foundation/rac_proto_adapters.cpp). The direct C-struct entry points never got the same check: rac_vlm_component_process (core/src/features/vlm/vlm_module.cpp:434) and rac_vlm_process (core/src/features/vlm/rac_vlm_service.cpp:144) only null-check the image before dispatching, and the llama.cpp backend calls mtmd_bitmap_init(image->width, image->height, image->pixel_data) at engines/llamacpp/rac_vlm_llamacpp.cpp:781-783 without ever consulting data_size.

Why it matters

A native caller that builds a rac_vlm_image_t directly (bypassing the proto path) with a short pixel_data buffer still triggers the same heap over-read #814 just closed for the proto path.

Suggested approach

In rac_vlm_process and rac_vlm_process_stream, reject RGB_PIXELS images unless width and height are positive, pixel_data is non-null, and data_size equals the overflow-checked width*height*3 -- reusing (or duplicating) the checked_raw_image_size logic from rac_proto_adapters.cpp.

Done when

  • rac_vlm_process rejects a RGB_PIXELS image whose data_size doesn't match width*height*3.
  • A regression test covers a native-built rac_vlm_image_t with a short buffer.

Not blocking #814. @shubhamsinnh, you know this code well now -- you're welcome to take this one if you're interested.

Opened with help from Claude Code and Codex.

Reviewed with help from Claude Code and Codex.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcoreC++ commons core (runanywhere-commons)securitySecurity vulnerability or hardening

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions