Skip to content

TiDB: improve validation for binary JSON input (#11195) - #11213

Merged
ti-chi-bot[bot] merged 1 commit into
pingcap:release-nextgen-202609from
ti-chi-bot:cherry-pick-11195-to-release-nextgen-202609
Nov 9, 2026
Merged

ti-chi-bot[bot] merged 1 commit into
pingcap:release-nextgen-202609from
ti-chi-bot:cherry-pick-11195-to-release-nextgen-202609

Conversation

@ti-chi-bot

@ti-chi-bot ti-chi-bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

This is an automated cherry-pick of #11195

What problem does this PR solve?

Issue Number: close #11194

Problem Summary: Some invalid binary JSON inputs are not handled correctly.

What is changed and how it works?

Improve binary JSON input validation and add regression tests.

Check List

  • Unit test (15 related tests passed)

Release note

Fix unexpected behavior with invalid binary JSON input.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of binary JSON objects and numeric values when data is incomplete or truncated, reporting an error instead of accessing data outside the available range.
    • Added coverage for valid object keys and numeric values across supported number types.

@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202609 labels Nov 4, 2026
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

getObjectKey and getValueEntry now use getSubRef to access binary JSON data. New tests check serialization of valid keys and numeric values, and verify that truncated input throws Exception.

Changes: Binary JSON bounds checks

Layer / File(s) Summary
Checked slices and regression tests
dbms/src/TiDB/Decode/JsonBinary.cpp, dbms/src/TiDB/tests/gtest_json_binary.cpp
getObjectKey and getValueEntry use getSubRef for their data slices. Tests cover valid object keys and numeric values, plus truncated inputs that throw Exception.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • pingcap/tiflash#11195: This PR makes the same getSubRef changes and adds the same binary JSON bounds tests.
  • pingcap/tiflash#11211: This PR describes the same bounds checks and regression tests for object keys and numeric values.

Suggested reviewers: yibin87, searise

Merge Risk: Minimal · up to b14f5

The change adds bounds checks without altering valid-input serialization. No merge-blocking issue was identified; merge after normal checks pass.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title says the PR improves validation for binary JSON input. The raw summary describes bounds checks via getSubRef in JsonBinary::getObjectKey and getValueEntry, plus regression tests for object k…
Description check Passed The description follows the repository template. It includes the problem section with a linked issue (#11194) and a summary of the problem. It has a commit-message block, a checked unit-test box with …
Linked Issues check Passed Issue #11194 is closed and completed. It provides historical context only. No active linked issue supplies coding requirements for this pull request.
Out of Scope Changes check Passed The changes stay within the stated intent to validate binary JSON input. getObjectKey and getValueEntry now use getSubRef for bounds checks. The added tests cover object-key and numeric-value bo…
Full details: Title check

Explanation

The title says the PR improves validation for binary JSON input. The raw summary describes bounds checks via getSubRef in JsonBinary::getObjectKey and getValueEntry, plus regression tests for object keys and numeric values. The title matches the main change. The title is specific and concise. It names the TiDB area and the PR number, which adds no meaning but does no harm.

Full details: Description check

Explanation

The description follows the repository template. It includes the problem section with a linked issue (#11194) and a summary of the problem. It has a commit-message block, a checked unit-test box with 15 related tests passing, and a release note. Several template items are left unchecked or unfilled, such as the side-effects and documentation checkboxes. The 'What is changed and how it works?' section is thin. It gives one commit-message line and does not explain the bounds-check approach or the new tests. Those gaps are non-critical, so the description is mostly complete.

Full details: Out of Scope Changes check

Explanation

The changes stay within the stated intent to validate binary JSON input. getObjectKey and getValueEntry now use getSubRef for bounds checks. The added tests cover object-key and numeric-value bounds.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

A rabbit checks each byte in place
A key must fit within its space
Eight bytes pass, or tests object
Short slices raise an Exception
The burrow guards each JSON nest

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f586c490-fa4a-4bd4-95ba-3264af2ff810
Commits

Reviewing files that changed from the base of the PR and between 71233f6 and b14f5b4.

Files selected for processing: 2
  • dbms/src/TiDB/Decode/JsonBinary.cpp
  • dbms/src/TiDB/tests/gtest_json_binary.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@windtalker windtalker 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.

lgtm

@ti-chi-bot ti-chi-bot Bot added cherry-pick-approved Cherry pick PR approved by release team. needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved and removed do-not-merge/cherry-pick-not-approved labels Nov 9, 2026
@ti-chi-bot

ti-chi-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gengliqi, windtalker

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [gengliqi,windtalker]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Nov 9, 2026
@ti-chi-bot

ti-chi-bot Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

[LGTM Timeline notifier]

Timeline:

  • 2026-11-09 12:10:23.237940468 +0000 UTC m=+1100547.863090743: ☑️ agreed by windtalker.
  • 2026-11-09 12:28:23.466002472 +0000 UTC m=+1101628.091152745: ☑️ agreed by gengliqi.

@ti-chi-bot
ti-chi-bot Bot merged commit eae4ea9 into pingcap:release-nextgen-202609 Nov 9, 2026
7 checks passed
@ti-chi-bot
ti-chi-bot Bot deleted the cherry-pick-11195-to-release-nextgen-202609 branch November 9, 2026 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-nextgen-202609

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants