Commit d83d398
committed
backup: harden snapshot encoder core per M1 review (single-use guard + edge tests)
claude review on PR #825 found no blocking issues; addressed the two
meaningful findings plus the cheap nits to harden the foundation the
M2-M5 adapter feed loops build on:
- WriteTo is now single-use: a second call fails closed with
ErrSnapshotBuilderReused rather than silently re-emitting the
already-written entries (a footgun once adapters feed the builder
in loops). Caller audit: the only callers of WriteTo/newSnapshotBuilder
are tests; the production caller lands with the M6 CLI, so no
existing call site relies on reuse.
- Add now size-checks from the user-buffer lengths BEFORE allocating
the framed key/value, so an oversize record fails closed without a
wasted allocation.
- countingWriter.Write uses the idiomatic if-err-nil guard for
consistency with the rest of the package.
Tests: empty-builder header-only round-trip (fresh-cluster restore
path), WriteTo reuse rejection, and a deterministic WriteTo byte-count
assertion in the single-entry round-trip. Extracted assertWriteByteCount
/ assertSingleEntry helpers to keep the round-trip test under the cyclop
budget.
The gemini medium findings (unbounded slice / seen-map memory, reflect
in binary.Write) are below the in-memory-sort bound the design already
tracks as the external-sort follow-up milestone; not addressed here.1 parent 69623d7 commit d83d398
2 files changed
Lines changed: 103 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
56 | 64 | | |
57 | 65 | | |
58 | 66 | | |
| |||
123 | 131 | | |
124 | 132 | | |
125 | 133 | | |
| 134 | + | |
126 | 135 | | |
127 | 136 | | |
128 | 137 | | |
| |||
141 | 150 | | |
142 | 151 | | |
143 | 152 | | |
144 | | - | |
145 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
146 | 158 | | |
147 | | - | |
| 159 | + | |
148 | 160 | | |
149 | | - | |
150 | | - | |
| 161 | + | |
151 | 162 | | |
152 | | - | |
| 163 | + | |
153 | 164 | | |
| 165 | + | |
154 | 166 | | |
155 | 167 | | |
156 | 168 | | |
157 | 169 | | |
158 | | - | |
| 170 | + | |
159 | 171 | | |
160 | 172 | | |
161 | 173 | | |
| |||
169 | 181 | | |
170 | 182 | | |
171 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
172 | 188 | | |
173 | 189 | | |
174 | 190 | | |
| |||
214 | 230 | | |
215 | 231 | | |
216 | 232 | | |
217 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
218 | 237 | | |
219 | 238 | | |
220 | 239 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
105 | 106 | | |
106 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
107 | 114 | | |
108 | 115 | | |
109 | 116 | | |
| |||
112 | 119 | | |
113 | 120 | | |
114 | 121 | | |
115 | | - | |
116 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
117 | 131 | | |
118 | | - | |
119 | | - | |
| 132 | + | |
| 133 | + | |
120 | 134 | | |
121 | | - | |
122 | | - | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
123 | 143 | | |
124 | | - | |
125 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
126 | 151 | | |
127 | 152 | | |
128 | 153 | | |
| |||
202 | 227 | | |
203 | 228 | | |
204 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
205 | 272 | | |
206 | 273 | | |
207 | 274 | | |
| |||
0 commit comments