Commit edc438eb

edc438eb45b5Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 5 files · +2 added · ~3 modified

Description

parse,codegen: string literal with embedded NUL preserves length

Three layers had to learn about NUL bytes inside string literals:

  • parser: escape_str encodes NUL as %00 so the AST text-format field doesn't truncate at the embedded byte
  • loader: unescape_str decodes %00 back to a NUL byte
  • codegen: c_string_literal detects NUL-containing strings and emits a heap-allocated copy (sp_str_alloc + memcpy + sp_str_set_len) so sp_str_byte_len returns the full length. Plain (&("\xff" "...")[1]) literals would fall back to strlen and stop at the embedded NUL; NUL-containing literals pay a one-time alloc per call site (uncommon in practice). Strings without NUL keep the static literal form.

Refs #722

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
edc438eb45b5
Parent
6ce9b20fd6de

node_table_loader.rbmodifiedView file

@@ -121,6 +121,9 @@
121121 result = result + " "
122122 when "25"
123123 result = result + "%"
124+ when "00"
125+ # Issue #722: NUL byte (literal embedded in a Ruby string).
126+ result = result + 0.chr
124127 else
125128 result = result + "%" + hex
126129 end