Repository navigation
bugfix: decode integers outside lua_Integer's range as floats - #133
Open
siliconwitch wants to merge 1 commit into
Open
siliconwitch wants to merge 1 commit into
siliconwitch wants to merge 1 commit into
Conversation
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
force-pushed
the
bugfix-large-integer-decode
branch
from
November 4, 2026 13:51
f27453a to
d758561
Compare
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On 32-bit builds of Lua 5.3+,
ptrdiff_tis narrower thanlua_Integer, so integers beyond ±2^31 decoded as floats.strtollalso saturates out-of-range input, so100000000000000000000decoded as9223372036854775807. CheckerrnoforERANGEand compare againstLUA_MAXINTEGER, falling back toPTRDIFF_MAXon Lua 5.1, 5.2 and LuaJIT.The new tests in
tests/test.luaandtests/agentzh.tfail 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