Skip to content

Add bounds checks to StringHelper::format placeholder handling#655

Merged
swebb2066 merged 1 commit into
apache:masterfrom
jmestwa-coder:stringhelper-format-bounds-checks
May 10, 2026
Merged

Add bounds checks to StringHelper::format placeholder handling#655
swebb2066 merged 1 commit into
apache:masterfrom
jmestwa-coder:stringhelper-format-bounds-checks

Conversation

@jmestwa-coder
Copy link
Copy Markdown
Contributor

Summary

Add bounds validation to StringHelper::format to safely handle malformed or under-supplied placeholders.

The previous implementation indexed pattern[i + 1], pattern[i + 2], and params[arg] without validating bounds, which could trigger invalid memory access and process failure for malformed format strings or missing arguments.

Changes

  • Replaced sentinel-style string iteration with length-checked iteration
  • Added bounds checks before reading placeholder characters
  • Added argument index validation before accessing params[arg]
  • Preserved unresolved placeholders literally when arguments are missing

Tests

Added regression coverage for:

  • empty format patterns
  • missing placeholder arguments

@swebb2066 swebb2066 merged commit 5dc9c0a into apache:master May 10, 2026
17 checks passed
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.

2 participants