Skip to content

search: validate PutMulti response length before building MultiError - #418

Open
Usamak06 wants to merge 1 commit into
golang:masterfrom
Usamak06:search-putmulti-response-length
Open

Usamak06 wants to merge 1 commit into
golang:masterfrom
Usamak06:search-putmulti-response-length

Conversation

@Usamak06

Copy link
Copy Markdown

Index.PutMulti sizes the returned MultiError to len(res.Status) and returns it with res.DocId as soon as a per-document status is non-OK, so the length check that guards against a short or mismatched IndexDocument response only runs on the success path and is skipped whenever the response also carries an error status. MultiError is documented as the same size as srcs with element i corresponding to srcs[i], so a mismatched response gives callers a MultiError whose indices no longer line up: iterating by source index panics with an out-of-range access or misattributes an error to the wrong document. DeleteMulti already validates len(res.Status) against the request before building its MultiError; this applies the same guard in PutMulti and keeps the DocId-length check on the success path.

Applied to the v2 module as well, with a regression test in both.

Index.PutMulti sizes the returned appengine.MultiError to len(res.Status)
and returns it (with res.DocId) as soon as any per-document status is
non-OK. The check that the response length matches the number of
documents sent only runs on the success path, so an IndexDocument
response that is shorter or longer than the request and also carries a
non-OK status skips it entirely.

MultiError is documented to be the same size as srcs with element i
corresponding to srcs[i], so a mismatched response hands callers a
MultiError whose indices no longer line up: code iterating by source
index panics with an out-of-range access, or attributes an error to the
wrong document.

DeleteMulti already guards against this by checking len(res.Status)
against the request before building its MultiError. Do the same in
PutMulti: validate len(res.Status) == len(docs) first and size the
MultiError to len(docs), keeping the DocId-length check on the success
path where the backend returns one ID per document.

Signed-off-by: usama khan <usama@bugqore.com>
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