Skip to content

fix(stringx): reject start > stop in Substr to prevent slice panic#5616

Open
SAY-5 wants to merge 1 commit into
zeromicro:masterfrom
SAY-5:fix/substr-start-stop-guard
Open

fix(stringx): reject start > stop in Substr to prevent slice panic#5616
SAY-5 wants to merge 1 commit into
zeromicro:masterfrom
SAY-5:fix/substr-start-stop-guard

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 31, 2026

Copy link
Copy Markdown

Closes #5607.

Substr validates start and stop individually against [0, length] but never checks that start <= stop, so calls like Substr("hello", 3, 2) slip past both guards and panic on rs[3:2]. Treat start > stop as an invalid stop position so callers get ErrInvalidStopPosition instead of a runtime panic.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

Substr panics with slice bounds out of range when start > stop

1 participant