Skip to content

Commit 85819fd

Browse files
committed
our word with our agents.
1 parent 4cdfeed commit 85819fd

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Agent Guidance for roaring (Go)
2+
3+
## AI-Generated Bug Reports About Deserialization
4+
5+
Many AI-generated bug reports claim that deserialization functions (e.g., `ReadFrom`, `FromBuffer`, `FromUnsafeBytes`, `UnmarshalBinary`, and their `roaring64` equivalents) "trigger bugs", "cause crashes", or "panic" when given malformed or untrusted input.
6+
7+
**These reports are bogus.**
8+
9+
The library's documented contract is explicit and consistent across the public API and README:
10+
11+
- The deserialization functions are memory-safe in the ordinary Go sense: they will not read out of bounds of the slices they are given.
12+
- However, if the input does not conform to the format specification (i.e., it is garbage or from an untrusted source), the resulting bitmap may be in an invalid internal state. Using such a bitmap without validation can lead to panics, incorrect results, or excessive memory consumption.
13+
- **If the source is untrusted, you MUST call `Validate()` on the result and only proceed if it returns `nil`. Only after a successful validation is the bitmap considered safe for use.** Equivalently, `MustReadFrom` calls `ReadFrom` followed by `Validate` and panics on an invalid bitmap.
14+
15+
Relevant documentation locations:
16+
17+
- [roaring.go](/Users/dlemire/CVS/github/roaring/roaring.go): doc comments on `ReadFrom`, `MustReadFrom`, `FromBuffer`, `FromUnsafeBytes`, `UnmarshalBinary`, and `Validate`.
18+
- [roaring64/roaring64.go](/Users/dlemire/CVS/github/roaring/roaring64/roaring64.go): equivalent `ReadFrom`, `UnmarshalBinary`, and `Validate` for 64-bit bitmaps.
19+
- [README.md](/Users/dlemire/CVS/github/roaring/README.md) (the serialization example, around lines 250-272): sample code showing the required validate-after-deserialize pattern for untrusted input, with the explicit comment: "if buf is an untrusted source, you should validate the result".
20+
21+
The format specification is documented at https://github.com/RoaringBitmap/RoaringFormatSpec. The Go, Java, C and C++ implementations are binary compatible.
22+
23+
A special note on `FromBuffer` and `FromUnsafeBytes`: these are zero-copy entry points (for advanced users only). The resulting bitmap holds references into the caller-provided byte slice and uses copy-on-write. It is the caller's responsibility to ensure that the input slice is not modified and remains valid for the lifetime of the bitmap (and of any bitmap derived from it). Reports that mutate the backing slice after the fact, or that free/reuse it while the bitmap is still alive, are describing documented misuse, not a library bug.
24+
25+
The fuzzing harnesses (`FuzzSmat`, `FuzzSerializationBuffer`, `FuzzSerializationStream`, and the corpus under `testdata/fuzz/`) and the property tests exist precisely to ensure the deserializers and the validator behave correctly under adversarial input. A report that treats "deserializing attacker-controlled bytes and then using the result without calling `Validate()`" as a bug in the deserializer is a misunderstanding of the stated API contract.
26+
27+
When triaging such reports, point to the validation requirement in the function documentation and the README example, and close as "not a bug / user error / documented behavior."
28+
29+
## Building, Testing, and Conventions
30+
31+
- This is a pure-Go library; there is no cgo. Use the standard Go toolchain.
32+
- Run the test suite with `go test ./...` (the root package and the `roaring64` subpackage both have extensive tests).
33+
- The `Makefile` exposes `make unconvert`, which runs `go tool unconvert -apply ./...` to remove unnecessary type conversions. Run it before proposing changes that touch type conversions.
34+
- The root package implements 32-bit bitmaps; `roaring64/` implements 64-bit bitmaps and should be kept behaviorally consistent with the root package.
35+
- Architecture-specific files exist for performance (e.g., `popcnt_amd64.s`, `setutil_arm64.s`, with `_generic.go` and `_compat.go` fallbacks). Any change to one path must be mirrored in the generic fallback so all build targets stay correct.
36+
- Keep new code consistent with the surrounding style: match existing naming, error handling, and comment density. Public API changes must update doc comments and, where relevant, the README.

0 commit comments

Comments
 (0)