fix: wrap malformed query scalar values in SerializationException#137
Open
OmarAlJarrah wants to merge 1 commit into
Open
fix: wrap malformed query scalar values in SerializationException#137OmarAlJarrah wants to merge 1 commit into
OmarAlJarrah wants to merge 1 commit into
Conversation
QueryDecoder's scalar decoders (Int/Long/Short/Byte/Double/Float/Char) converted the raw query string directly with toInt()/toLong()/single() etc., so a malformed value threw the raw JVM/stdlib exception (NumberFormatException, NoSuchElementException, IllegalArgumentException) straight out of decodeFromQueryParameters instead of the SerializationException the format's own enum-decoding path and the Url/Uri serializers already guarantee. A caller catching SerializationException around decode, the documented failure boundary for untrusted query input, would not catch these. Switch each conversion to the *OrNull stdlib variant and fail with a descriptive SerializationException when it returns null, mirroring how the existing enum path resolves an unknown value. Applied to both the top-level QueryDecoder and the list-element QueryListDecoder paths. Closes #83
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.
Summary
QueryDecoder's scalar decoders (decodeInt/decodeLong/decodeShort/decodeByte/decodeDouble/decodeFloat/decodeChar) converted the raw query string directly withtoInt()/toLong()/single()etc., so a malformed value let the raw JVM/stdlib exception (NumberFormatException,NoSuchElementException,IllegalArgumentException) escapedecodeFromQueryParametersinstead of theSerializationExceptionthe format's enum-decoding path and theUrl/Uriserializers already guarantee.try { ... } catch (e: SerializationException)— the documented pattern for validating untrusted query input — would not catch these.*OrNullstdlib variant and fail with a descriptiveSerializationExceptionwhen it returns null, mirroring how the existing enum path resolves an unknown value. Applied to both the top-levelQueryDecoderand the list-elementQueryListDecoderpaths.Test plan
SerdeTest.ktcovering malformedInt(page=abc), emptyInt, malformedLong/Short/Byte/Double/Float, emptyChar, multi-characterChar(charValue=ab), and a malformed list element — confirmed each fails before the fix and passes after./gradlew :kuri-serde-kotlinx:jvmTest :kuri-serde-kotlinx:ktlintCheck :kuri-serde-kotlinx:detekt :kuri-serde-kotlinx:apiCheck./gradlew :kuri-serde-kotlinx:jsNodeTest(commonMain touched)wasmJsNodeTest(known to transiently OOM the Kotlin daemon in this environment when bundled with other targets) — unverified on wasminternal), soapiDumpwas not needed;apiCheckconfirms no diffCloses #83