Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigquery: handleInsertErrors: equality check should be >=, not > #3519

Closed
muscovite opened this issue Jan 9, 2021 · 3 comments · Fixed by #3524
Closed

bigquery: handleInsertErrors: equality check should be >=, not > #3519

muscovite opened this issue Jan 9, 2021 · 3 comments · Fixed by #3524
Assignees
Labels
api: bigquery Issues related to the BigQuery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@muscovite
Copy link

muscovite commented Jan 9, 2021

Client

BigQuery Go API

Environment

All

Go Environment

All

Code

https://github.com/googleapis/google-cloud-go/blob/bigquery/v1.14.0/bigquery/inserter.go#L226

The > check

 if int(e.Index) > len(rows)

should be >=

 if int(e.Index) >= len(rows)

Otherwise, the next lines can attempt to access an out of range index:

rie := RowInsertionError{
	InsertID: rows[e.Index].InsertId,
	RowIndex: int(e.Index),
}

Expected behavior

No out of bounds errors

Actual behavior

panic: runtime error: index out of range [1] with length 1

goroutine 1432095 [running]:/vendor/cloud.google.com/go/bigquery.handleInsertErrors(0xc0002c8500, 0x3e8, 0x42a, 0xc000012708, 0x1, 0x1, 0x0, 0xc00f377ce8)
        ...vendor/cloud.google.com/go/bigquery/inserter.go:236 +0x56a/vendor/cloud.google.com/go/bigquery.(*Inserter).putMulti(0xc00029a7a0, 0xdbd580, 0xc04648e8d0, 0xc04649c200, 0x1, 0x1, 0x0, 0xdbd580)
        .../vendor/cloud.google.com/go/bigquery/inserter.go:191 +0x3b1/vendor/cloud.google.com/go/bigquery.(*Inserter).Put(0xc00029a7a0, 0xdbd580, 0xc04648e870, 0xb6edc0, 0xc00023c980, 0x0, 0x0)
... // the rest of the stack trace is no longer in library code
@muscovite muscovite added the triage me I really want to be triaged. label Jan 9, 2021
@product-auto-label product-auto-label bot added the api: bigquery Issues related to the BigQuery API. label Jan 9, 2021
@shollyman
Copy link
Contributor

Thanks for the report. Just to verify, were you seeing this behavior against the live service, or was this purely a byproduct of testing?

shollyman added a commit to shollyman/google-cloud-go that referenced this issue Jan 11, 2021
External reporter identified case where improper bounds checking can
cause panic when comparing the index value from structured error
response.

Fixes: googleapis#3519
@muscovite
Copy link
Author

Thanks for the fix! This was seen against the live service. For full context, though, the API caller does something fairly hacky where the row data is passed through http.RoundTripper as gzip-compressed bytes, and the src arg to Put is a single dummy row. So I think it's unlikely that "normal" API usage would have run into this issue.

@shollyman
Copy link
Contributor

Ahh ok, that would explain it. I was worried this was a signal of further issues with the backend. Will work on getting that fix submitted and released.

@shollyman shollyman added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. labels Jan 12, 2021
shollyman added a commit that referenced this issue Jan 12, 2021
…eInsertErrors (#3524)

* fix: address possible panic due to offset checking in handleInsertErrors

External reporter identified case where improper bounds checking can
cause panic when comparing the index value from structured error
response.

Fixes: #3519
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
2 participants