docstore/awsdynamodb: fix panic on empty in/not-in filter value - #3754
Merged
vangent merged 1 commit intoJul 23, 2026
Merged
Conversation
toInCondition unconditionally indexed into the filter value slice
(vslice.Index(0)) without checking its length. docstore's own
Where() validator (validFilterSlice) accepts an empty slice as a
valid value for the in/not-in operators, so a query built with an
empty slice (e.g. Where("x", "in", []string{})) panicked with
"reflect: slice index out of range" during query planning, with
no recover() anywhere in the call path.
Handle the empty case by building an always-false condition, which
Not() turns into always-true for not-in, matching how other docstore
backends (mongodocstore's $in/$nin, for example) already treat an
empty in-list.
go test ./docstore/... passes.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3754 +/- ##
=========================================
Coverage ? 75.33%
=========================================
Files ? 104
Lines ? 14204
Branches ? 0
=========================================
Hits ? 10700
Misses ? 2767
Partials ? 737 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
toInCondition unconditionally does vslice.Index(0) on the filter value:
https://github.com/google/go-cloud/blob/master/docstore/awsdynamodb/v2/query.go#L449
docstore's own Where() validator (validFilterSlice, in docstore/query.go) accepts an empty slice as a valid value for the in/not-in operators, since its bounds-check loop never executes for a zero-length slice. A query built with an empty slice, e.g. Where("category", "in", []string{}), reaches toInCondition with a zero-length slice and panics with "reflect: slice index out of range" during query planning, before any network call, with nothing in docstore or this package recovering it.
This handles the zero-length case by building an always-false condition instead of indexing into the empty slice. Not() of that gives an always-true condition for not-in, matching the usual "x IN ()" / "x NOT IN ()" semantics (consistent with how mongodocstore's $in/$nin already treats an empty list).
Added a regression test. go test ./docstore/... passes.