Skip to content

stdlib: print/io of a non-UTF-8 binary raises where PUC-Lua writes raw bytes #409

Description

@davydog187

Found during automated differential review of PR #406 (not caused by it).

print (and io writes) of a binary that is not valid UTF-8 raises Lua.RuntimeException (:io.put_chars argument error) where PUC-Lua 5.3 writes the raw bytes:

print(("日本"):gsub("^.", "X"))  -- crashes; the gsub result itself is byte-identical to PUC

Lua strings are byte strings; any byte-slicing produces non-UTF-8 binaries routinely, so this affects ordinary programs. Likely fix: write via IO.binwrite/latin1-safe path instead of :io.put_chars with unicode translation.

🤖 Filed from an automated review pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions