Commit cacd448
committed
backup: hash field array shape + 32-bit safety + kindByKey centralisation (PR #725, round 1)
Codex round 12 raised two P1 findings on commit 72e2b75; Gemini
raised one high and three mediums alongside.
P1: Hash field name encoding via JSON object key was lossy.
- Distinct fields could collapse to the same JSON key: a UTF-8
literal `%FF` and a single binary byte `0xFF` both ended up
as `%FF` after the EncodeSegment-on-non-UTF-8 fallback,
silently dropping data on hashes with both forms.
- Long binary field names (>240 bytes) hit EncodeSegment's
SHA fallback which is irreversible at this layer (no
per-field KEYMAP), so restore could not reconstruct the
original bytes.
Fix: change `fields` to a JSON array of typed `{name, value}`
records. Both name and value go through the same UTF-8-or-base64
envelope (marshalRedisBinaryValue, mirrors PR #714's SQS body),
so arbitrary binary bytes round-trip without collisions and
without SHA fallback.
High (Gemini): parseUserKeyLenPrefix used `int(uint32)` which
wraps to negative on 32-bit when the high bit is set, bypassing
the bounds check and causing a slice panic. Compare in `uint64`
space before converting.
Medium (Gemini, ×3): centralise `kindByKey` registration in the
hashState helper so meta/field/TTL paths agree on the kind in
one place. Audited callers — HandleHashMeta, HandleHashField, and
HandleTTL's `case redisKindHash:` arm — all reach hashState via
the same userKey identity, and the TTL caller already knows the
kind so the now-implicit kindByKey write is idempotent. No other
callers per `grep -n "r\.hashState(" internal/backup/`.
Tests:
- TestRedisDB_HashRoundTripBasic updated to assert the array
shape via new hashFieldArray / hashFieldByName helpers.
- TestRedisDB_HashEmptyHashStillEmitsFile, _BinaryFieldValue
updated likewise.
- NEW TestRedisDB_HashBinaryFieldNameRoundTripsViaArray drives
the exact Codex collision pair (UTF-8 `%FF` + binary 0xFF)
and asserts both names survive distinctly with their
expected types.
Verified: linux race tests, GOOS=windows, GOOS=js wasm, lint —
all clean.1 parent 72e2b75 commit cacd448
2 files changed
Lines changed: 170 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
| |||
80 | 79 | | |
81 | 80 | | |
82 | 81 | | |
83 | | - | |
84 | 82 | | |
85 | 83 | | |
86 | 84 | | |
87 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
88 | 99 | | |
89 | | - | |
| 100 | + | |
| 101 | + | |
90 | 102 | | |
91 | 103 | | |
92 | 104 | | |
93 | | - | |
| 105 | + | |
| 106 | + | |
94 | 107 | | |
95 | 108 | | |
96 | 109 | | |
| |||
122 | 135 | | |
123 | 136 | | |
124 | 137 | | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
125 | 143 | | |
126 | 144 | | |
127 | 145 | | |
128 | 146 | | |
129 | | - | |
130 | | - | |
| 147 | + | |
| 148 | + | |
131 | 149 | | |
132 | 150 | | |
133 | | - | |
| 151 | + | |
134 | 152 | | |
135 | 153 | | |
136 | 154 | | |
| |||
186 | 204 | | |
187 | 205 | | |
188 | 206 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
196 | 226 | | |
197 | 227 | | |
198 | | - | |
199 | | - | |
| 228 | + | |
200 | 229 | | |
201 | 230 | | |
202 | 231 | | |
203 | 232 | | |
204 | 233 | | |
| 234 | + | |
205 | 235 | | |
206 | | - | |
207 | | - | |
208 | | - | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
209 | 239 | | |
210 | 240 | | |
211 | 241 | | |
212 | 242 | | |
213 | 243 | | |
214 | | - | |
| 244 | + | |
215 | 245 | | |
216 | 246 | | |
217 | | - | |
218 | | - | |
219 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
220 | 250 | | |
221 | 251 | | |
222 | 252 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
74 | 79 | | |
75 | | - | |
| 80 | + | |
76 | 81 | | |
77 | | - | |
| 82 | + | |
78 | 83 | | |
79 | | - | |
| 84 | + | |
80 | 85 | | |
81 | | - | |
| 86 | + | |
82 | 87 | | |
83 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
84 | 110 | | |
85 | 111 | | |
86 | 112 | | |
| |||
105 | 131 | | |
106 | 132 | | |
107 | 133 | | |
108 | | - | |
109 | | - | |
110 | | - | |
| 134 | + | |
| 135 | + | |
111 | 136 | | |
112 | | - | |
113 | | - | |
| 137 | + | |
| 138 | + | |
114 | 139 | | |
115 | 140 | | |
116 | 141 | | |
| |||
126 | 151 | | |
127 | 152 | | |
128 | 153 | | |
129 | | - | |
130 | | - | |
131 | | - | |
| 154 | + | |
| 155 | + | |
132 | 156 | | |
133 | 157 | | |
134 | 158 | | |
| |||
206 | 230 | | |
207 | 231 | | |
208 | 232 | | |
209 | | - | |
210 | | - | |
| 233 | + | |
| 234 | + | |
211 | 235 | | |
212 | | - | |
| 236 | + | |
213 | 237 | | |
214 | 238 | | |
215 | 239 | | |
216 | 240 | | |
217 | 241 | | |
218 | 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 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
219 | 318 | | |
220 | 319 | | |
221 | 320 | | |
| |||
0 commit comments