Skip to content

bugfix: decode integers outside lua_Integer's range as floats - #133

Open
siliconwitch wants to merge 1 commit into
openresty:masterfrom
siliconwitch:bugfix-large-integer-decode
Open

siliconwitch wants to merge 1 commit into
openresty:masterfrom
siliconwitch:bugfix-large-integer-decode

Conversation

@siliconwitch

@siliconwitch siliconwitch commented Nov 4, 2026 •

Copy link
Copy Markdown

On 32-bit builds of Lua 5.3+, ptrdiff_t is narrower than lua_Integer, so integers beyond ±2^31 decoded as floats. strtoll also saturates out-of-range input, so 100000000000000000000 decoded as 9223372036854775807. Check errno for ERANGE and compare against LUA_MAXINTEGER, falling back to PTRDIFF_MAX on Lua 5.1, 5.2 and LuaJIT.

The new tests in tests/test.lua and tests/agentzh.t fail before this change and pass after it on Lua 5.1, 5.2, 5.3, 5.4 and LuaJIT with gcc and clang, and on 32-bit Lua 5.4.

🤖 Generated with Claude Code

On 32-bit builds of Lua 5.3+, ptrdiff_t is narrower than lua_Integer, so
integers beyond +/-2^31 decoded as floats. strtoll also saturates
out-of-range input, so 100000000000000000000 decoded as
9223372036854775807. Check errno for ERANGE and compare against
LUA_MAXINTEGER.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@siliconwitch
siliconwitch force-pushed the bugfix-large-integer-decode branch from f27453a to d758561 Compare November 4, 2026 13:51
@siliconwitch

Copy link
Copy Markdown
Author

Hey there!

Apologies for the AI generated description. Claude jumped the gun before I could write a proper description. Force pushed to add AI attribution note to the commit note also.

Anyway, I hit this issue on a 32-bit ARM Cortex-M33 running Lua 5.5 with 64-bit integers. Any integer beyond ±2^31 decoded as a float, and larger values lost precision. The saturation case affects every platform. Wasn't an issue for me but felt like it was worth adding. Feel free to tweak if needed.

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