|
| 1 | +--[[ |
| 2 | +SPDX-License-Identifier: ISC |
| 3 | +Copyright (c) 2023-2025, Sergey Bronnikov. |
| 4 | +
|
| 5 | +2.5.4 – Concatenation |
| 6 | +https://www.lua.org/manual/5.1/manual.html |
| 7 | +
|
| 8 | +Recording of __concat in GC64 mode, |
| 9 | +https://github.com/LuaJIT/LuaJIT/issues/839 |
| 10 | +
|
| 11 | +Bug: Unbalanced Stack After Hot Instruction error on table concatenation, |
| 12 | +https://github.com/LuaJIT/LuaJIT/issues/690 |
| 13 | +
|
| 14 | +LJ_GC64: Fix lua_concat(), |
| 15 | +https://github.com/LuaJIT/LuaJIT/issues/881 |
| 16 | +
|
| 17 | +Buffer overflow in string concatenation, |
| 18 | +https://github.com/lua/lua/commit/5853c37a83ec66ccb45094f9aeac23dfdbcde671 |
| 19 | +
|
| 20 | +Wrong assert when reporting concatenation errors |
| 21 | +(manifests only when Lua is compiled in debug mode). |
| 22 | +https://www.lua.org/bugs.html#5.2.2-3 |
| 23 | +
|
| 24 | +Wrong error message in some concatenations, |
| 25 | +https://www.lua.org/bugs.html#5.1.2-5 |
| 26 | +
|
| 27 | +Concat metamethod converts numbers to strings, |
| 28 | +https://www.lua.org/bugs.html#5.1.1-8 |
| 29 | +
|
| 30 | +String concatenation may cause arithmetic overflow, leading to |
| 31 | +a buffer overflow, |
| 32 | +https://www.lua.org/bugs.html#5.0.2-1 |
| 33 | +]] |
| 34 | + |
| 35 | +local luzer = require("luzer") |
| 36 | +local test_lib = require("lib") |
| 37 | + |
| 38 | +local function TestOneInput(buf) |
| 39 | + local fdp = luzer.FuzzedDataProvider(buf) |
| 40 | + local str = fdp:consume_string(test_lib.MAX_STR_LEN) |
| 41 | + if str == nil then return -1 end |
| 42 | + local str_chars = {} |
| 43 | + str:gsub(".", function(c) table.insert(str_chars, c) end) |
| 44 | + |
| 45 | + local str_concat = "" |
| 46 | + for _, c in ipairs(str_chars) do |
| 47 | + str_concat = str_concat .. c |
| 48 | + end |
| 49 | + assert(str_concat == str) |
| 50 | +end |
| 51 | + |
| 52 | +local args = { |
| 53 | + artifact_prefix = "builtin_concat_", |
| 54 | +} |
| 55 | +luzer.Fuzz(TestOneInput, nil, args) |
0 commit comments