Guard against null iterator in toMap to prevent SIGSEGV#84
Open
ericraio wants to merge 1 commit intoapple:mainfrom
Open
Guard against null iterator in toMap to prevent SIGSEGV#84ericraio wants to merge 1 commit intoapple:mainfrom
ericraio wants to merge 1 commit intoapple:mainfrom
Conversation
### Motivation:
`cass_iterator_from_map` can return NULL when the column value is non-null
but not a valid map type (e.g., corrupted data or type mismatch). The existing
null check on the column value (`cass_value_is_null`) does not cover this case.
When `cass_iterator_next` is called with a NULL iterator, it dereferences a null
pointer causing a SIGSEGV (Signal 11, exit code 139) crash.
This was observed in production where API server pods repeatedly crashed when
decoding map columns from Cassandra rows with unexpected data states.
### Modifications:
Changed `let iterator = cass_iterator_from_map(self.rawPointer)` to
`guard let iterator = cass_iterator_from_map(self.rawPointer) else { return nil }`
in the `toMap` method. This matches the defensive pattern already used in
`Data.swift` for `cass_iterator_from_collection`.
### Result:
When `cass_iterator_from_map` returns NULL, `toMap` now safely returns `nil`
instead of crashing with a null pointer dereference. Callers that access map
properties will get `nil` and can fall back to alternative decoding paths.
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.
Motivation:
cass_iterator_from_mapcan return NULL when the column value is non-null but not a valid map type (e.g., corrupted data or type mismatch). The existing null check on the column value (cass_value_is_null) does not cover this case. Whencass_iterator_nextis called with a NULL iterator, it dereferences a null pointer causing a SIGSEGV (Signal 11, exit code 139) crash.This was observed where the server repeatedly crashed when decoding map columns from Cassandra rows with unexpected data states.
Modifications:
Changed
let iterator = cass_iterator_from_map(self.rawPointer)toguard let iterator = cass_iterator_from_map(self.rawPointer) else { return nil }in thetoMapmethod. This matches the defensive pattern already used inData.swiftforcass_iterator_from_collection.Result:
When
cass_iterator_from_mapreturns NULL,toMapnow safely returnsnilinstead of crashing with a null pointer dereference. Callers that access map properties will getniland can fall back to alternative decoding paths.