Skip to content

fix(core): bound Markdown directive whitespace scanning - #1926

Merged
phernandez merged 9 commits into
mainfrom
codex/security-markdown-token-work
Oct 28, 2026
Merged

phernandez merged 9 commits into
mainfrom
codex/security-markdown-token-work

Conversation

@phernandez

Copy link
Copy Markdown
Member

Why

The terminal #bm:links_to regex retries a leading whitespace run at every position when no directive follows. A 150,000-space token exceeds a five-second subprocess deadline. Fixes #1900.

What Changed

Use a single-character whitespace boundary before the literal directive instead of a repeated leading whitespace group. Existing callers trim the prefix, preserving directive-removal behavior.

Implementation Details

Only the fixed literal can initiate a trailing-whitespace match, so failed whitespace suffixes cannot overlap quadratically. Both observation parsing and code-aware relation directive handling share the corrected pattern. A subprocess bounds regression runtime without mocking the parser.

Stacked on #1925; only the shared directive pattern and its tests are new here.

Testing

  • Before the fix: the whitespace-heavy regression timed out after five seconds.
  • uv run pytest tests/markdown/test_directive_work.py tests/markdown/test_markdown_plugins.py -q --no-cov: passed.
  • Semantics tests cover Unicode whitespace, terminal newlines, missing separators, and nonterminal directives.
  • just fast-check: passed, including repository type checking.
  • just doctor: passed sandboxed write/index/search self-test.

Risks / Follow-ups

The shared pattern's match start now points at the directive instead of its leading whitespace; both consumers already trim the prefix, so returned content remains identical. Broader Markdown parser work remains outside this PR.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T21:40:59.716775Z 420978e Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@phernandez
phernandez force-pushed the codex/security-atomic-staging branch from 6e59a28 to d74bce5 Compare October 28, 2026 21:12
@phernandez
phernandez force-pushed the codex/security-markdown-token-work branch from 2217761 to 420978e Compare October 28, 2026 21:12
@phernandez

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 420978ead9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Base automatically changed from codex/security-atomic-staging to main October 28, 2026 22:18
@phernandez
phernandez changed the base branch from codex/security-atomic-staging to main October 28, 2026 22:18
@phernandez
phernandez merged commit 1ea3276 into main Oct 28, 2026
50 checks passed
@phernandez
phernandez deleted the codex/security-markdown-token-work branch October 28, 2026 22:23
phernandez added a commit that referenced this pull request Oct 28, 2026
## Why

A CSV header controls the width used to pad every retained row. The
existing output limit is checked only after building the expanded table.
A 5 KiB source with 5,000 columns and 200 short rows allocates over 9
MiB before rejection. Fixes #1912.

## What Changed

Pass the configured output budget into preview rendering and count the
exact projected UTF-8 Markdown size before table padding and rendering.
Reuse the existing configured limit and error type.

## Implementation Details

The projection includes header/separator widths, padded cells, escaped
pipes/backslashes, CRLF flattening, line endings, and the row-count
footer. This keeps normal preview output byte-identical while preventing
header-driven amplification. Empty-file previews also honor their output
budget.

Stacked on #1926; only CSV preview budgeting and its tests are new here.

## Testing

- Before the fix: the bounded public-extractor regression recorded more
than 9 MiB of allocation and failed its 1 MiB ceiling.
- `uv run pytest tests/document_ingestion/test_csv_preview_budget.py
tests/document_ingestion/test_csv_extractor.py -q --no-cov`: 24 passed.
- Exact-byte budget tests cover empty, ASCII, escaped Unicode, CRLF, and
ragged rows without mocks.
- `just fast-check`: passed, including repository type checking.
- `just doctor`: passed sandboxed write/index/search self-test.

## Risks / Follow-ups

No new budget value or file-size policy: the existing
CsvLimits.max_output_bytes now applies before output construction. The
source and field limits continue to bound decoding and parsing.

---------

Signed-off-by: phernandez <[email protected]>
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.

Make Markdown token whitespace parsing linear

1 participant