Skip to content

caddyfile: avoid quadratic heredoc marker scanning - #8203

Merged
steadytao merged 1 commit into
masterfrom
fix-heredoc-tokenize-timeout
Oct 12, 2026
Merged

steadytao merged 1 commit into
masterfrom
fix-heredoc-tokenize-timeout

Conversation

@francislavoie

Copy link
Copy Markdown
Member

Long heredoc markers made tokenization repeatedly convert and compare the entire marker-sized suffix after every body rune. A captured 501 KB fuzz testcase exceeded a five-second timeout; it now returns an incomplete-heredoc error in approximately 15 ms.

Use incremental KMP matching to scan the body in linear time while preserving existing marker semantics. Add regression coverage for long markers, overlapping prefixes, Unicode and invalid UTF-8 bodies, incomplete heredocs, and raw-source preservation, plus a benchmark. The costly comparison predates #7880.

Validation:

  • go test -race -short -timeout 120s ./... passed with local socket access.
  • go build -buildvcs=false ./... passed.
  • golangci-lint run --timeout 10m passed with zero issues.
  • A 10-second FuzzFormatSemanticPreserve run passed 28,139 executions.
  • Original captured testcase replay completed in approximately 15 ms.

AI assistance: OpenAI Codex (GPT-6) generated and tested this change.

@francislavoie francislavoie added the bug ๐Ÿž Something isn't working label Oct 12, 2026
@francislavoie francislavoie added this to the v2.12.0 milestone Oct 12, 2026

@steadytao steadytao left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers. LGTM.

@steadytao
steadytao merged commit 7328273 into master Oct 12, 2026
30 checks passed
@steadytao
steadytao deleted the fix-heredoc-tokenize-timeout branch October 12, 2026 10:52
zhaikong pushed a commit to zhaikong/caddy that referenced this pull request Oct 15, 2026
zhaikong pushed a commit to zhaikong/caddy that referenced this pull request Oct 31, 2026
zhaikong pushed a commit to zhaikong/caddy that referenced this pull request Oct 31, 2026
This was referenced Nov 3, 2026
NickCao pushed a commit to NickCao/caddy that referenced this pull request Nov 4, 2026
@francislavoie francislavoie modified the milestones: v2.12.0, v2.11.8 Nov 4, 2026
zhaikong pushed a commit to zhaikong/caddy that referenced this pull request Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ๐Ÿž Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants