|
| 1 | +--[=[[ |
| 2 | +SPDX-License-Identifier: ISC |
| 3 | +Copyright (c) 2023-2025, Sergey Bronnikov. |
| 4 | +
|
| 5 | +6.5 – UTF-8 Support |
| 6 | +https://www.lua.org/manual/5.3/manual.html#6.5 |
| 7 | +
|
| 8 | +'utf8.codes' does not raise an error on spurious continuation bytes, |
| 9 | +https://github.com/lua/lua/commit/a1089b415a3f5c753aa1b40758ffdaf28d5701b0 |
| 10 | +
|
| 11 | +Synopsis: utf8.codepoint(s [, i [, j [, lax]]]) |
| 12 | +]]=] |
| 13 | + |
| 14 | +local luzer = require("luzer") |
| 15 | +local test_lib = require("lib") |
| 16 | +local MAX_INT = test_lib.MAX_INT |
| 17 | + |
| 18 | +-- The function is introduced in Lua 5.3. |
| 19 | +if test_lib.lua_current_version_lt_than(5, 3) then |
| 20 | + os.exit() |
| 21 | +end |
| 22 | + |
| 23 | +local function TestOneInput(buf) |
| 24 | + local fdp = luzer.FuzzedDataProvider(buf) |
| 25 | + local max_len = fdp:consume_integer(1, MAX_INT) |
| 26 | + local s = fdp:consume_string(max_len) |
| 27 | + local i = fdp:consume_integer(0, MAX_INT) |
| 28 | + local j = fdp:consume_integer(0, MAX_INT) |
| 29 | + local lax = fdp:consume_integer(1, MAX_INT) |
| 30 | + os.setlocale(test_lib.random_locale(fdp), "all") |
| 31 | + pcall(utf8.codepoint, s, i, j, lax) |
| 32 | +end |
| 33 | + |
| 34 | +local args = { |
| 35 | + artifact_prefix = "utf8_codepoint_", |
| 36 | +} |
| 37 | +luzer.Fuzz(TestOneInput, nil, args) |
0 commit comments