Skip to content

fix(stdlib): enforce max_string_bytes in print, string.char, utf8.char and debug.traceback - #440

Open
davydog187 wants to merge 1 commit into
mainfrom
fix/print-string-ceiling
Open

davydog187 wants to merge 1 commit into
mainfrom
fix/print-string-ceiling

Conversation

@davydog187

Copy link
Copy Markdown
Contributor

Follow-up to #426.

  • print counted nothing: 64 references to a 1 MiB string made one 67 MB write at a 1 MiB ceiling. It now tracks the line size as it assembles it and raises "resulting string too large" before writing (0 bytes written in the probe).
  • string.char, utf8.char and debug.traceback refuse an oversized result before building it (traceback per frame, so a deep stack is refused early).
  • error() position prefix: documented, not fixed. The message was already within the ceiling and the prefix is chunk name plus a few bytes, constant, not growing with arguments or frames; refusing would replace the user's error with a size error.
  • string.format: dropped the width pre-check (and padded_width/1), so a bad argument reports its own error under a tiny ceiling; costs at most 99 bytes. This also removes the displaced comment block.
  • The :max_string_bytes doc no longer says "any single string" and lists what it does not bound.
  • CHANGELOG entry added.

Tests: new test/lua/vm/builder_ceiling_test.exs (red before, green after). Full suite: 2779 tests; one BootstrapTest flake on one run, which passes alone and on re-run.

…r and debug.traceback

print joined all of its arguments with no check, so a script could make one
write far past the ceiling. It now counts the line as it assembles it and
raises before writing. string.char, utf8.char and debug.traceback refuse an
oversized result before building it.

string.format no longer pre-checks a conversion's width, which restores the
bad-argument error order under a ceiling smaller than the width at a cost of
at most 99 bytes. The max_string_bytes option doc now names what the ceiling
does not bound (the error() position prefix, one in-flight format piece).
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.

1 participant