Skip to content

fix: guard against divide-by-zero in unmarshalVector when Dimensions is 0#771

Closed
mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul:fix-vector-unmarshal-zero-dimensions
Closed

fix: guard against divide-by-zero in unmarshalVector when Dimensions is 0#771
mykaul wants to merge 1 commit intoscylladb:masterfrom
mykaul:fix-vector-unmarshal-zero-dimensions

Conversation

@mykaul
Copy link
Copy Markdown

@mykaul mykaul commented Mar 13, 2026

Summary

  • unmarshalVector computes elemSize = len(data) / info.Dimensions without checking for zero dimensions, causing a runtime panic on the generic reflect-based path
  • Adds an early guard after the data == nil check: returns an empty slice for empty data with 0 dimensions, or a descriptive error when non-empty data is paired with 0 dimensions
  • Adds 3 unit test cases covering nil data, empty data, and non-empty data with 0-dimension vectors

Context

This is a pre-existing bug in the generic unmarshalVector path, not introduced by any recent PR. It was identified during review of PR #770 (vector marshal optimization) but exists independently on master.

The fast-path code in #770 is not affected since its type-specialized functions handle the dimension count via len(data) / elemByteSize (byte size is always > 0 for float32/float64/int32/int64).

…is 0

unmarshalVector computes elemSize = len(data) / info.Dimensions without
checking for zero dimensions, causing a panic on the generic reflect-based
path. Add an early guard that returns an empty slice for empty data, or a
descriptive error when non-empty data is paired with 0 dimensions.
@mykaul mykaul closed this Mar 13, 2026
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