Skip to content

fix: keep emoji escape tail bounded#142

Merged
liuq19 merged 2 commits into
masterfrom
fix/jsonpath-header-self-contained
Jul 17, 2026
Merged

fix: keep emoji escape tail bounded#142
liuq19 merged 2 commits into
masterfrom
fix/jsonpath-header-self-contained

Conversation

@liuq19

@liuq19 liuq19 commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • stop emoji escaping at the end of a truncated or invalid UTF-8 tail
  • add an ASAN-backed regression test for the bounded-input case
  • authenticate same-repository pull request coverage uploads with Codecov OIDC while preserving tokenless uploads for forks

Root cause

When fewer than four bytes remained, DoEscape copied one raw byte and used continue. That skipped the nb == 0 termination check, allowing the loop to read beyond the input and eventually underflow the remaining length.

Scope

  • include/sonic/internal/arch/common/quote_common.h
  • tests/quote_test.cpp
  • .github/workflows/test_coverage.yml

No public API changes. The unrelated JSONPath, header self-containment, and broader CI changes from the earlier revision were removed.

Validation

  • regression test on the old implementation reproduced an AddressSanitizer heap-buffer-overflow
  • ASAN_OPTIONS=detect_leaks=0 ./build/tests/unittest '--gtest_filter=Quote.*' --gtest_brief=1 — 3/3 passed
  • ASAN_OPTIONS=detect_leaks=0 ./build/tests/unittest --gtest_brief=1 — 303/303 passed
  • git diff --check origin/master...HEAD
  • actionlint .github/workflows/test_coverage.yml
  • GitHub Actions Test Coverage run 29555640052 — passed, including the Codecov OIDC upload

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown

Benchmark

Mode: informational
Warning threshold: >3% regression
Critical threshold: >10% regression
Included benchmarks: Sonic

Severity Benchmark base real_time head real_time delta
warning gsoc-2018/Decode_SonicDyn 815850.33 ns 840928.79 ns +3.07%
warning gsoc-2018/Encode_SonicDyn 559328.12 ns 590324.40 ns +5.54%
info lottie/Stat_SonicDyn 197180.82 ns 189035.25 ns -4.13%
warning poet/Encode_SonicDyn 630690.54 ns 661932.44 ns +4.95%

Overall severity: warning

Conclusion: informational only. Benchmark regressions are reported in this summary/artifact and do not block the workflow.

@codecov-commenter

codecov-commenter commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.67%. Comparing base (966f9d5) to head (f8d8094).

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.
📢 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.

@liuq19
liuq19 force-pushed the fix/jsonpath-header-self-contained branch from 6610afd to 62a7766 Compare July 17, 2026 03:45
@liuq19 liuq19 changed the title fix: harden jsonpath edge cases fix: keep emoji escape tail bounded Jul 17, 2026
@liuq19
liuq19 marked this pull request as ready for review July 17, 2026 04:36
Copilot AI review requested due to automatic review settings July 17, 2026 04:36

Copilot AI 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.

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 DoEscape control flow so the nb == 0 termination 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.

@yangzhg yangzhg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@liuq19
liuq19 merged commit ee76cf2 into master Jul 17, 2026
29 checks passed
@liuq19
liuq19 deleted the fix/jsonpath-header-self-contained branch July 17, 2026 05:53
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.

4 participants