MCPcopy
hub / github.com/buger/jsonparser / TestObjectEach_OOB_TruncatedAfterComma

Function TestObjectEach_OOB_TruncatedAfterComma

dead_code_audit_oob_test.go:11–24  ·  view source on GitHub ↗

Test that ObjectEach doesn't panic with out-of-bounds access after removing the `offset < len(data)` loop guard. Verifies: SYS-REQ-007 [boundary]

(t *testing.T)

Source from the content-addressed store, hash-verified

9
10// Verifies: SYS-REQ-007 [boundary]
11func TestObjectEach_OOB_TruncatedAfterComma(t *testing.T) {
12 // {"a":1, — truncated right after comma, no more data
13 // After parsing "a":1, finds comma at step 4, increments offset past comma.
14 // Then step "skip to next token after comma" calls nextToken on remaining data.
15 // If remaining is empty → nextToken returns -1 → returns MalformedArrayError.
16 // No panic.
17 err := ObjectEach([]byte(`{"a":1,`), func(key []byte, value []byte, dataType ValueType, offset int) error {
18 return nil
19 })
20 if err == nil {
21 t.Fatal("expected error for truncated object after comma")
22 }
23 t.Logf("Correctly got error: %v", err)
24}
25
26// Verifies: SYS-REQ-007 [boundary]
27func TestObjectEach_OOB_TruncatedAfterColon(t *testing.T) {

Callers

nothing calls this directly

Calls 1

ObjectEachFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…