Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

fix(detector): finalizeEntity panics with slice bounds out of range

Open Beginner friendly
#626 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
66/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go
Domain
security

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

bug

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: if end < start or end > 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dataiku/kiji-proxy

All issues in dataiku/kiji-proxy

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.