@@ -366,3 +366,32 @@ func TestPointersInDecoder(t *testing.T) {
366366 })
367367 }
368368}
369+
370+ // TestBoundsChecking verifies that buffer access is properly bounds-checked
371+ // to prevent panics on malformed databases.
372+ func TestBoundsChecking (t * testing.T ) {
373+ // Create a very small buffer that would cause out-of-bounds access
374+ // if bounds checking is not working
375+ smallBuffer := []byte {0x44 , 0x41 } // Type string (0x4), size 4, but only 2 bytes total
376+ dd := NewDataDecoder (smallBuffer )
377+ decoder := & Decoder {d : dd , offset : 0 }
378+
379+ // This should fail gracefully with an error instead of panicking
380+ _ , err := decoder .DecodeString ()
381+ require .Error (t , err )
382+ require .Contains (t , err .Error (), "exceeds buffer length" )
383+
384+ // Test DecodeBytes bounds checking
385+ _ , err = decoder .decodeBytes (TypeBytes )
386+ require .Error (t , err )
387+ require .Contains (t , err .Error (), "exceeds buffer length" )
388+
389+ // Test DecodeUInt128 bounds checking
390+ largeBuffer := []byte {0x0B , 0x01 } // Type uint128 (0x0), size 11, but only 2 bytes total
391+ dd2 := NewDataDecoder (largeBuffer )
392+ decoder2 := & Decoder {d : dd2 , offset : 0 }
393+
394+ _ , _ , err = decoder2 .DecodeUInt128 ()
395+ require .Error (t , err )
396+ require .Contains (t , err .Error (), "exceeds buffer length" )
397+ }
0 commit comments