Skip to content

fix(oracle): guard SUBSTRB end boundary - #1848

Open
yyqdbngt wants to merge 1 commit into
IvorySQL:masterfrom
yyqdbngt:codex/substrb-end-boundary
Open

fix(oracle): guard SUBSTRB end boundary#1848
yyqdbngt wants to merge 1 commit into
IvorySQL:masterfrom
yyqdbngt:codex/substrb-end-boundary

Conversation

@yyqdbngt

@yyqdbngt yyqdbngt commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary - stop SUBSTRB from calling pg_mblen after reaching the end of a multibyte varlena payload - cover a substring ending exactly at the UTF-8 source boundary ## Testing - git diff --check Closes #1844 ## Summary by CodeRabbit * Bug Fixes * Corrected byte-based substring handling for multibyte text. * SUBSTRB now returns the complete string when the requested byte length ends exactly at a multibyte character boundary. * Tests * Added regression coverage for SUBSTRB('你好', 1, 6), confirming the expected result.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 73b46818-f48e-41dd-8b07-d47e27d97ad2

📥 Commits

Reviewing files that changed from the base of the PR and between 42ed378 and 1a43518.

📒 Files selected for processing (3)
  • contrib/ivorysql_ora/expected/ora_character_datatype_functions.out
  • contrib/ivorysql_ora/sql/ora_character_datatype_functions.sql
  • contrib/ivorysql_ora/src/builtin_functions/character_datatype_functions.c

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The multibyte SUBSTRB loop now prevents boundary overrun during character traversal. Regression coverage verifies that a six-byte limit returns the complete UTF-8 string 你好.

Changes

SUBSTRB multibyte boundary handling

Layer / File(s) Summary
Guard multibyte boundary traversal
contrib/ivorysql_ora/src/builtin_functions/character_datatype_functions.c
The text_substring_byte loop now checks subStrEnd before advancing past the requested end position.
Add exact-boundary regression coverage
contrib/ivorysql_ora/sql/ora_character_datatype_functions.sql, contrib/ivorysql_ora/expected/ora_character_datatype_functions.out
The regression test verifies that SUBSTRB('你好', 1, 6) = '你好' evaluates to t.

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

Merge Risk: ⚪ Minimal · up to 1a435

This change prevents SUBSTRB from inspecting beyond a multibyte input boundary and adds coverage for an exact UTF-8 byte boundary. The implementation and regression expectation align, with no remaining merge-blocking risk.

Suggested reviewers: ai-yang, hs-liuxh

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation guards the multibyte SUBSTRB boundary before advancing and inspecting the next character. The SQL and expected-output changes add regression coverage for a UTF-8 substring that ends…
Out of Scope Changes check ✅ Passed All changes are directly related to issue #1844. The implementation change and regression test cover the SUBSTRB multibyte boundary defect. No unrelated code changes are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (2 skipped: 2 …
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing the Oracle SUBSTRB end-boundary handling.
Full details: Linked Issues check

Explanation

The implementation guards the multibyte SUBSTRB boundary before advancing and inspecting the next character. The SQL and expected-output changes add regression coverage for a UTF-8 substring that ends at the source boundary. These changes satisfy issue #1844.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (2 skipped: 2 unsupported.)

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@hanjianqiao

Copy link
Copy Markdown
Collaborator

Thank you for this patch! We'll review it shortly.

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.

SUBSTRB can inspect past the end of multibyte input

2 participants