Repository navigation
fix(core): bound find-replace output before allocation - #1923
Merged
Merged
Conversation
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
Signed-off-by: phernandez <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
find_replaceallocates the expanded string before any output budget is checked. A bounded reproduction expanded a 4 KiB note and a 4 KiB replacement to 16 MiB. Slightly larger inputs exceed that output size. Fixes #1897.What Changed
Cap the projected replacement result at 16 MiB of UTF-8 text and reject larger results before
str.replace. This policy applies only tofind_replace; attachment uploads and other note operations keep their existing behavior. Document the limit inbm-edit(3).Implementation Details
After validating the exact nonoverlapping replacement count, compute the current UTF-8 byte length plus count times the replacement/find byte-length difference. This accounts for multibyte text and shrinking edits without constructing the expanded output. The 16 MiB budget matches the hosted proxy request-size budget; the user approved a limit specifically for find/replace.
Stacked on #1922, following #1921 and #1920. Only the replacement budget, manual update, and tests are new here.
Testing
uv run pytest tests/services/test_find_replace_budget.py tests/services/test_entity_service.py tests/services/test_note_section_edits.py -q --no-cov: 102 passed.uv run pytest tests/mcp/test_tool_edit_note.py tests/api/v2/test_accepted_note_atomicity.py -q --no-cov: 81 passed.just fast-check: passed, including repository type checking.just doctor: passed sandboxed write/index/search self-test.git diff --check: passed.Risks / Follow-ups
Find/replace calls whose immediate replacement output exceeds 16 MiB are now refused in both local and hosted Core. The budget covers the replacement result, before later metadata/frontmatter preparation. This is an operation budget, not a general note or binary-file size limit. Cloud must update its Core dependency after merge to receive the guard.