Skip to content

clamp vsnprintf result before copying in log_printf - #9398

Open
Nashit-h wants to merge 2 commits into
halide:mainfrom
Nashit-h:hexagon-log-vsnprintf-clamp
Open

clamp vsnprintf result before copying in log_printf#9398
Nashit-h wants to merge 2 commits into
halide:mainfrom
Nashit-h:hexagon-log-vsnprintf-clamp

Conversation

@Nashit-h

Copy link
Copy Markdown
Contributor
  1. vsnprintf returns the length the message would have been, not the number of bytes written into the 1024-byte stack buffer, so a formatted string longer than that leaves message_size pointing past the buffer.
  2. global_log.write() then copies message[0..message_size-1] out of the buffer, and those bytes are handed back to the host through halide_hexagon_remote_poll_log.
    Clamp message_size to the bytes that actually fit (and bail on the negative error return) before the copy. log_printf backs halide_print/halide_error on the DSP, so an over-long printed or error string reaches it.

@codecov

codecov Bot commented Aug 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.19%. Comparing base (347b0d1) to head (1dd7b11).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9398      +/-   ##
==========================================
+ Coverage   70.14%   70.19%   +0.04%     
==========================================
  Files         261      261              
  Lines       79388    79396       +8     
  Branches    19357    19358       +1     
==========================================
+ Hits        55690    55729      +39     
- Misses      17874    17885      +11     
+ Partials     5824     5782      -42     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mcourteaux mcourteaux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, although I believe the fix is not 100% correct.

Comment thread src/runtime/hexagon_remote/qurt/log.cpp

@alexreinking alexreinking left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the usage manually. Thanks for catching the problem in the first place!

@alexreinking
alexreinking dismissed mcourteaux’s stale review August 29, 2026 17:39

I made the requested changes.

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

Successfully merging this pull request may close these issues.

3 participants