vaxis

created pr with 95.1 on 2025-12-16T16:06:41Z · by c8ef7d19
added 95.2 on 2025-12-16T16:07:53Z · by c8ef7d19
1: 37f44c1 ! 1: 7a2f7ff fix(vxfw/list): check if index is out of bounds
cmds
checkout latest patchset:
ssh pr.pico.sh print 95 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print 95.[rev] | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 95

Patchset 95.2 on 2025-12-16T16:07:53Z · commit 7a2f7ff

fix(vxfw/list): check if index is out of bounds
Eric Bower 2025-12-16T16:03:32Z
```
panic: runtime error: index out of range [64976] with length 64792

goroutine 53 [running]:
git.sr.ht/~rockorager/vaxis/vxfw.(*Surface).WriteCell(...)
     /go/pkg/mod/git.sr.ht/~rockorager/vaxis@v0.14.1-0.20250527151737-5530f9f4bcf6/vxfw/vxfw.go:158
git.sr.ht/~rockorager/vaxis/vxfw/list.(*Dynamic).Draw(0x40005c9f08, {{0xb?, 0x0?}, {0x0?, 0x0?}, 0x40000309a0?})
     /go/pkg/mod/git.sr.ht/~rockorager/vaxis@v0.14.1-0.20250527151737-5530f9f4bcf6/vxfw/list/list.go:210 +0xca8
```
Semantic diff summary
1 added, 1 modified, 0 signature changed, 0 removed across 2 analyzed files
+37 -0 vxfw/surface_test.go #
......@@ -0,0 +1,37 @@
1+package vxfw_test
2+
3+import (
4+ "testing"
5+
6+ "git.sr.ht/~rockorager/vaxis"
7+ "git.sr.ht/~rockorager/vaxis/vxfw"
8+)
9+
10+func TestWriteCellBoundsCheck(t *testing.T) {
11+ // Create a surface where Size claims more cells than Buffer actually has.
12+ // This simulates the bug where Size and Buffer get out of sync.
13+ s := vxfw.Surface{
14+ Size: vxfw.Size{
15+ Width: 100,
16+ Height: 100,
17+ },
18+ Buffer: make([]vaxis.Cell, 50), // Only 50 cells, but Size claims 10000
19+ }
20+
21+ cell := vaxis.Cell{
22+ Character: vaxis.Character{
23+ Grapheme: "x",
24+ Width: 1,
25+ },
26+ }
27+
28+ // This should not panic even though the index would be out of bounds
29+ // if we only checked against Size.
30+ s.WriteCell(99, 99, cell) // Would calculate index 9999, but Buffer only has 50 cells
31+
32+ // Also test that valid writes still work
33+ s.WriteCell(0, 0, cell)
34+ if s.Buffer[0].Character.Grapheme != "x" {
35+ t.Errorf("expected cell at (0,0) to be written, got %q", s.Buffer[0].Character.Grapheme)
36+ }
37+}
+3 -0 vxfw/vxfw.go #
......@@ -155,6 +155,9 @@ func (s *Surface) WriteCell(col uint16, row uint16, cell vaxis.Cell) {
155155 return
156156 }
157157 i := (row * s.Size.Width) + col
158+ if int(i) >= len(s.Buffer) {
159+ return
160+ }
158161 s.Buffer[i] = cell
159162 }
160163
Back to top