fix: keep emoji escape tail bounded#142
Conversation
BenchmarkMode:
Overall severity: Conclusion: informational only. Benchmark regressions are reported in this summary/artifact and do not block the workflow. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #142 +/- ##
=======================================
Coverage 69.67% 69.67%
=======================================
Files 27 27
Lines 3706 3706
Branches 1189 1189
=======================================
Hits 2582 2582
Misses 211 211
Partials 913 913 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
6610afd to
62a7766
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a bounds bug in the scalar quote/escape path when kSerializeEscapeEmoji is enabled and the remaining input tail is shorter than 4 bytes, preventing out-of-bounds reads/length underflow. Adds a regression test to exercise the bounded-input tail case under ASAN.
Changes:
- Adjust
DoEscapecontrol flow so thenb == 0termination check is not skipped for short (<4 bytes) tails in emoji-escape mode. - Add a unit test that validates emoji escaping stops at the end of an invalid/truncated UTF-8 tail without over-reading.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| include/sonic/internal/arch/common/quote_common.h | Fixes DoEscape loop control to keep the remaining-length check effective when fewer than 4 bytes remain. |
| tests/quote_test.cpp | Adds an ASAN-friendly regression test covering the short invalid tail case for kSerializeEscapeEmoji. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Root cause
When fewer than four bytes remained,
DoEscapecopied one raw byte and usedcontinue. That skipped thenb == 0termination check, allowing the loop to read beyond the input and eventually underflow the remaining length.Scope
include/sonic/internal/arch/common/quote_common.htests/quote_test.cpp.github/workflows/test_coverage.ymlNo public API changes. The unrelated JSONPath, header self-containment, and broader CI changes from the earlier revision were removed.
Validation
heap-buffer-overflowASAN_OPTIONS=detect_leaks=0 ./build/tests/unittest '--gtest_filter=Quote.*' --gtest_brief=1— 3/3 passedASAN_OPTIONS=detect_leaks=0 ./build/tests/unittest --gtest_brief=1— 303/303 passedgit diff --check origin/master...HEADactionlint .github/workflows/test_coverage.ymlTest Coveragerun29555640052— passed, including the Codecov OIDC upload