Skip to content

Correct sequence repetition and bound allocation sizes - #28

Closed
qoke wants to merge 2 commits into
ardanlabs:mainfrom
iqhive:jinjafix-sequence-repetition-limits
Closed

qoke wants to merge 2 commits into
ardanlabs:mainfrom
iqhive:jinjafix-sequence-repetition-limits

Conversation

@qoke

@qoke qoke commented Oct 22, 2026

Copy link
Copy Markdown

Closes #23.

String and list repetition mishandled some operand orders and negative counts. Large counts could also overflow size calculations or request excessive allocations. Repeating an empty list by a huge count could loop despite the result being empty.

Repetition now uses shared handling that supports the sequence on either side of multiplication, treats negative counts as zero, and returns empty results immediately. For nonempty sequences, a division-based size check avoids overflow before calculating the repeated length and allocating memory.

Results are limited to 1 << 26 string bytes or list elements. Exceeding that limit returns a controlled rendering error. This is an engine resource policy, not a limit shared with Python.

The seven regression cases cover operand order, negative counts, excessive sizes, and empty-list repetition with a huge count. They include Python reference results and the original Go failures. Supported cases now match Python, while excessive-size cases return controlled errors.

@ardan-bkennedy

Copy link
Copy Markdown
Contributor

Thank you, @qoke, for reporting these issues and for providing proposed fixes. We reviewed all nine reports and used your suggestions where they made sense in the codebase. All nine issues have now been resolved in #34, each with corresponding regression tests, and the fixes are published in v1.11.0.

The issue addressed by this PR (#23) is covered by that release, so we are closing this PR in favor of the consolidated fix.

For future reports, please start with issues only so we can discuss the approach before opening pull requests. Thanks again for helping improve the project.

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.

Correct sequence repetition and bound allocation sizes

2 participants