Repository navigation
Commit d456df0
Bound decoder work to prevent a pointer fan-out denial of service
A crafted data section could nest pointers to shared targets so that
decoding one record cost exponential time and memory from a small file
(GHSA-hj94-g986-h9r7).
The decoder now limits the number of values it decodes for a single record
and rejects a database that exceeds the limit with an InvalidDatabaseError.
The limit is 65,536, far above the few hundred values the largest real
records decode. Pointer cycles and over-deep data are rejected the same way
rather than exhausting the stack. The limit state is call-local, so the
decoder stays safe for concurrent reads. This matches the reader resource
limits now recommended by the MaxMind DB specification.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 8fc70e4 commit d456df0
4 files changed
Lines changed: 222 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
6 | 16 | | |
7 | 17 | | |
8 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
22 | 39 | | |
23 | 40 | | |
24 | 41 | | |
| |||
42 | 59 | | |
43 | 60 | | |
44 | 61 | | |
45 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
46 | 74 | | |
47 | 75 | | |
48 | | - | |
| 76 | + | |
49 | 77 | | |
| 78 | + | |
50 | 79 | | |
51 | 80 | | |
52 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
53 | 87 | | |
54 | 88 | | |
55 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
56 | 95 | | |
57 | 96 | | |
58 | 97 | | |
59 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
60 | 104 | | |
61 | 105 | | |
62 | 106 | | |
63 | 107 | | |
64 | 108 | | |
65 | 109 | | |
66 | | - | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
67 | 116 | | |
68 | 117 | | |
69 | 118 | | |
70 | 119 | | |
71 | 120 | | |
72 | 121 | | |
73 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
74 | 128 | | |
75 | 129 | | |
76 | 130 | | |
| |||
81 | 135 | | |
82 | 136 | | |
83 | 137 | | |
84 | | - | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
85 | 151 | | |
86 | 152 | | |
87 | | - | |
88 | | - | |
| 153 | + | |
| 154 | + | |
89 | 155 | | |
| 156 | + | |
90 | 157 | | |
91 | 158 | | |
92 | | - | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
93 | 165 | | |
94 | 166 | | |
95 | 167 | | |
| |||
109 | 181 | | |
110 | 182 | | |
111 | 183 | | |
112 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
113 | 192 | | |
114 | 193 | | |
115 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
116 | 200 | | |
117 | 201 | | |
118 | 202 | | |
119 | 203 | | |
120 | | - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
121 | 210 | | |
122 | 211 | | |
123 | 212 | | |
| |||
144 | 233 | | |
145 | 234 | | |
146 | 235 | | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
147 | 250 | | |
148 | 251 | | |
149 | 252 | | |
| |||
160 | 263 | | |
161 | 264 | | |
162 | 265 | | |
163 | | - | |
| 266 | + | |
164 | 267 | | |
165 | 268 | | |
166 | 269 | | |
| |||
- .github/workflows/codeql-analysis.yml+3-3
- .gitignore+1
- MaxMind-DB-spec.md+135
- README.md+6
- cmd/write-test-data/main.go+5
- go.mod+3-5
- go.sum+2-2
- pkg/writer/pointerdos.go+502
- pkg/writer/pointerdos_test.go+598
- pkg/writer/rawmmdb.go+74-16
- pkg/writer/rawmmdb_test.go+190
- test-data/MaxMind-DB-test-decode-path-shared-budget.mmdb
- test-data/MaxMind-DB-test-decoder-payload-limit-over.mmdb
- test-data/MaxMind-DB-test-decoder-payload-limit.mmdb
- test-data/MaxMind-DB-test-decoder-value-limit-over.mmdb
- test-data/MaxMind-DB-test-decoder-value-limit-pointer-heavy.mmdb
- test-data/MaxMind-DB-test-decoder-value-limit.mmdb
- test-data/MaxMind-DB-test-metadata-payload-limit.mmdb
- test-data/MaxMind-DB-test-payload-amplification-dos-string.mmdb
- test-data/MaxMind-DB-test-payload-amplification-dos-worst-case.mmdb
- test-data/MaxMind-DB-test-payload-amplification-dos.mmdb
- test-data/MaxMind-DB-test-pointer-decoder-dos-ipv6.mmdb
- test-data/MaxMind-DB-test-pointer-decoder-dos.mmdb
- test-data/README.md+77
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
12 | 18 | | |
13 | 19 | | |
14 | 20 | | |
| |||
232 | 238 | | |
233 | 239 | | |
234 | 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 | + | |
| 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 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
0 commit comments