fix(detector): finalizeEntity panics with slice bounds out of range
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 66/100
Research direction
The panic comes from the slice originalText[startOffset[0]:endOffset[1]] in finalizeEntity in src/backend/pii/detectors/onnx_model_detector.go, around line 669. Start by reading how tokenIndices are grouped into an entity and why a trailing special token with offset (0,0) can end up in it. Done means a regression test in the detectors package, using an offsets slice whose last token is (0,0), passes without panicking, and the entity text is correct or the entity is dropped.
Written by the indexing model from the issue text.
Description
Summary
ONNXModelDetectorSimple.finalizeEntity can panic with slice bounds out of range when the last token of an entity has an end offset smaller than the first token's start offset. The HTTP handler recovers, but the request fails.
Observed
During an e2e run (make test-e2e) against a dev backend, two requests panicked:
http: panic serving 127.0.0.1:56203: runtime error: slice bounds out of range [22:0]
...
github.com/dataiku/kiji-proxy/src/backend/pii/detectors.(*ONNXModelDetectorSimple).finalizeEntity(...)
src/backend/pii/detectors/onnx_model_detector.go:669
The second showed [55:0]. The :0 end suggests the entity's last token is a special or zero-length token (e.g. [SEP] or padding with offset (0,0)) that was grouped into the entity.
Code
src/backend/pii/detectors/onnx_model_detector.go:669:
startOffset := offsets[tokenIndices[0]]
endOffset := offsets[tokenIndices[len(tokenIndices)-1]]
entity.Text = originalText[startOffset[0]:endOffset[1]]
There is no check that endOffset[1] >= startOffset[0], or that both are within len(originalText).
Suggested fix
- Skip zero-length or special tokens (offset
(0,0)after the first position) when grouping tokens into entities, and/or - Clamp in
finalizeEntity: ifend < startorend > len(originalText), drop the trailing bad tokens (or the entity) instead of slicing. - Add a regression test with an offsets slice whose last token is
(0,0).
- Dominant language
- Go
- Stars
- 438
- Forks
- 51
- Avg merge
- 3d 2h
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dataiku/kiji-proxy
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
dataiku/kiji-proxy#635 ·
Maintainers usually reply within 4 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
dataiku/kiji-proxy#629 ·
Maintainers usually reply within 4 days
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
dataiku/kiji-proxy#596 · 1 comment ·
Maintainers usually reply within 4 days
-
internationalization
Difficulty 2/5 1-2 days Newbie friendliness 68/100
dataiku/kiji-proxy#575 ·
Maintainers usually reply within 4 days
-
Add Go package-level doc comments to src/backend/providers/May be free again @min-ok claimed this 18 days ago, and no pull request is open. Opengood first issue
Difficulty 2/5 Under an hour Newbie friendliness 84/100
dataiku/kiji-proxy#427 · 1 comment ·
Maintainers usually reply within 4 days
All issues in dataiku/kiji-proxy
Similar issues
-
🕷️ bug
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
sysadminsmedia/homebox#1805 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
router-for-me/CLIProxyAPI#6851 ·
Maintainers usually reply within 1 day
-
usage: a custom provider's balance meters ("…%" in the balance path) ignore the Left/Used switchOpen
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
[bug]: docs: Update webhook delete examples to use the correct flag (--webhook-id)Possibly taken @MuhammadHassan968 claimed this today. Openbug
Difficulty 1/5 Under an hour Newbie friendliness 84/100
goharbor/harbor-cli#1127 ·
Maintainers usually reply within 12 days