Skip to content

manager: guard parseKernelVersion against non-Int version fields - #3593

Open
palazik wants to merge 1 commit into
tiann:mainfrom
palazik:fix/kernel-version-parse-overflow
Open

manager: guard parseKernelVersion against non-Int version fields#3593
palazik wants to merge 1 commit into
tiann:mainfrom
palazik:fix/kernel-version-parse-overflow

Conversation

@palazik

@palazik palazik commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

parseKernelVersion pulls three numeric groups out of the version string and calls .toInt() on each:

KernelVersion(find.groupValues[1].toInt(), find.groupValues[2].toInt(), find.groupValues[3].toInt())

The input is Os.uname().release, which isn't guaranteed to be sane. If any captured field is longer than Int.MAX_VALUE can hold, toInt() throws NumberFormatException and takes the app down, even though the function already has a (-1, -1, -1) sentinel for the "no match" case.

Switched to toIntOrNull() and fall back to that same sentinel when a field can't be parsed, so a strange release string just reads as an unknown version instead of crashing.

parseKernelVersion fed each regex group straight into toInt(). The
groups come from uname().release, and a field that doesn't fit in an Int
throws NumberFormatException, which is an uncaught crash rather than the
(-1,-1,-1) sentinel the function already uses for "couldn't parse".

Use toIntOrNull() and fall back to the sentinel if any field overflows.
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