Skip to content

Fix SemVerCmp overflow on 32-bit targets (dependencies never resolve) - #10

Open
kylep33 wants to merge 1 commit into
KindleModding:mainfrom
kylep33:fix-semvercmp-32bit
Open

kylep33 wants to merge 1 commit into
KindleModding:mainfrom
kylep33:fix-semvercmp-32bit

Conversation

@kylep33

@kylep33 kylep33 commented Nov 12, 2026 •

Copy link
Copy Markdown

Problem

On a 32-bit Kindle (kpm v0.2.4), installing any package whose dependencies have no explicit "max" fails:

[ERR] Could not find artifact for kambience-sounds-1 (0.0.0 - 4294967295.4294967295.4294967295)
[ERR] Could not construct graph for kambience

This happens even though the dependency is in the index and installs fine on its own, and even after it's already installed.

Cause

SemVerCmp returns (long) a.x - (long) b.x. On 32-bit ARM, long is 32 bits, so (long) UINT_MAX is -1. A missing "max" defaults to VERSION_MAX (UINT_MAX), so SemVerCmp(1.0.0, max) gives 1 - (-1) = 2 > 0. The range check in Internal_ConstructGraphFromArtifact then rejects every indexed and installed artifact.

Fix

Compare the fields instead of subtracting them, returning -1/0/1. All callers only check the sign. The new tests/kpm_semver_test.c includes SemVerCmp(1.0.0, SEMVER_MAX) < 0. I confirmed that this assertion fails when the old function is compiled with a 32-bit long and passes with the fix.

Workaround until this is released: give each dependency an explicit range, e.g. {"id": "foo", "min": [1, 0, 0], "max": [2, 0, 0]}.

SemVerCmp subtracted (long) casts of unsigned ints. On 32-bit Kindles long is
32 bits, so (long) UINT_MAX is -1 and every version compared greater than the
default max (SEMVER_MAX). Any dependency without an explicit "max" was then
rejected with "Could not find artifact for <id> (0.0.0 - 4294967295...)",
even when the artifact was indexed or already installed.

Compare instead of subtracting, and add a SemVer test.
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.

2 participants