Artifact 5fb43d3bf395e0c90bba6b8d5dd4d77ec65aa89cf850db4f942ea13b5153a655:
- File
internal/delta/example_test.go
— part of check-in
[38eddf43f1]
at
2026-10-11 23:34:08
on branch main
— fix(delta): refuse a source or target of 2^32 bytes or more in Create (#279) (#320)
The delta format holds integers below 2^32 only, so a producer must not write a target length or copy offset at or past that. Create now returns ErrTooLarge for such inputs; Deltify then stores the content whole, as fossil does when a delta is not worthwhile, and the other callers propagate the error. Apply's header check becomes >= so it refuses exactly what Create will not write. The bound is tested on lengths, as a direct test needs a 4 GiB input. (user: [email protected], size: 737) [annotate] [blame] [check-ins using]
package delta_test import ( "fmt" "github.com/danmestas/go-libfossil/internal/delta" ) func ExampleCreate() { source := []byte("the quick brown fox jumps over the lazy dog\n") target := []byte("the quick brown fox leaps over the lazy dog\n") d, err := delta.Create(source, target) if err != nil { fmt.Println("error:", err) return } // Delta is smaller than storing the full target. fmt.Printf("delta smaller: %v\n", len(d) < len(target)) // Apply reconstructs the target from source + delta. reconstructed, err := delta.Apply(source, d) if err != nil { fmt.Println("error:", err) return } fmt.Print(string(reconstructed)) // Output: // delta smaller: true // the quick brown fox leaps over the lazy dog }