Skip to content

Fix index out of bounds panic when map collection has odd items#412

Open
dkropachev wants to merge 1 commit intomasterfrom
dk/fix-map-collection-odd-items-panic
Open

Fix index out of bounds panic when map collection has odd items#412
dkropachev wants to merge 1 commit intomasterfrom
dk/fix-map-collection-odd-items-panic

Conversation

@dkropachev
Copy link
Contributor

@dkropachev dkropachev commented Feb 2, 2026

Summary

  • Fixes index out of bounds panic in map collection to CassCqlValue conversion when a map has an odd number of items (missing value in a key-value pair)
  • Changes From<&CassCollection> to TryFrom<&CassCollection> for CassCqlValue, returning CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE instead of panicking
  • Updates binding.rs to use try_into() to propagate the error to callers
  • Logs an error via tracing::error! when an odd-item map is encountered
  • Adds Vec::with_capacity for map pair allocation
  • Adds unit test covering both odd (error) and even (success) item counts

Fixes #411

Test plan

  • Run cargo test collection:: to verify all collection tests pass
  • Run make check-cargo-clippy check-cargo-fmt to verify linting passes

@dkropachev dkropachev force-pushed the dk/fix-map-collection-odd-items-panic branch from 6ab67c4 to 67809e2 Compare February 2, 2026 09:51
@dkropachev dkropachev force-pushed the dk/fix-map-collection-odd-items-panic branch from 67809e2 to 7c72cbb Compare February 2, 2026 13:42
Maps require key-value pairs, so an odd number of items is invalid.
Changed From<&CassCollection> to TryFrom<&CassCollection> to return
CASS_ERROR_LIB_INVALID_VALUE_TYPE for malformed map collections.

Fixes #411
@dkropachev dkropachev force-pushed the dk/fix-map-collection-odd-items-panic branch from 7c72cbb to eb49e87 Compare February 3, 2026 02:37
@dkropachev
Copy link
Contributor Author

Regarding the review comment about returning an error instead of ignoring odd-item maps:

Done. Changed the implementation to return an error:

  1. Changed impl From<&CassCollection> to impl TryFrom<&CassCollection> with type Error = CassError
  2. Added validation that returns Err(CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE) when the map has an odd number of items
  3. Updated binding.rs to use try_into().map(Some) to properly propagate the error
  4. Added unit test that verifies the error is returned for odd-item maps

@wprzytula
Copy link
Contributor

@dkropachev Please update the cover letter.

@dkropachev
Copy link
Contributor Author

@dkropachev Please update the cover letter.

done

@dkropachev dkropachev requested a review from Lorak-mmk February 8, 2026 03:08
@dkropachev
Copy link
Contributor Author

@Lorak-mmk , could you please review it ?

@dkropachev
Copy link
Contributor Author

Just in case, cicd failure not related to this PR.

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.

Index out of bounds error when iterating collections with 3 elements

3 participants