Commit f513807
authored
fix: prevent StackOverflowError from deeply nested GeometryCollection in GeoJsonParser (#1699)
* fix: prevent StackOverflowError from deeply nested GeometryCollection
Add MAX_GEOMETRY_DEPTH = 20 limit to parseGeometry() to prevent
StackOverflowError when parsing malicious GeoJSON with deeply nested
GeometryCollection objects.
Geometries exceeding the depth limit are silently ignored and a
warning is logged via Log.w().
* test: add unit tests for MAX_GEOMETRY_DEPTH limit in GeoJsonParser
Add three tests to GeoJsonParserTest to verify the fix for
StackOverflowError caused by deeply nested GeometryCollection objects
(introduced in the accompanying fix commit):
- testDeeplyNestedGeometryCollection_doesNotThrowStackOverflow:
Ensures parsing 2000-level nesting no longer throws StackOverflowError
- testGeometryBeyondMaxDepth_returnsNull:
Ensures geometry exceeding MAX_GEOMETRY_DEPTH (20) returns null
instead of crashing
- testShallowNestedGeometryCollection_parsedCorrectly:
Ensures normal shallow nesting still parses correctly (regression guard)
Relates to: #1699
* test: remove duplicate testGeometryBeyondMaxDepth_returnsNull superseded by dkhawk's commit
* fix: apply dkhawk's changes - countdown maxDepth and updated tests1 parent ea2094c commit f513807
2 files changed
Lines changed: 77 additions & 5 deletions
File tree
- library/src
- main/java/com/google/maps/android/data/geojson
- test/java/com/google/maps/android/data/geojson
Lines changed: 16 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
180 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
181 | 192 | | |
182 | 193 | | |
183 | 194 | | |
| |||
190 | 201 | | |
191 | 202 | | |
192 | 203 | | |
193 | | - | |
| 204 | + | |
194 | 205 | | |
195 | 206 | | |
196 | 207 | | |
| |||
239 | 250 | | |
240 | 251 | | |
241 | 252 | | |
242 | | - | |
| 253 | + | |
243 | 254 | | |
244 | 255 | | |
245 | 256 | | |
| |||
255 | 266 | | |
256 | 267 | | |
257 | 268 | | |
258 | | - | |
| 269 | + | |
259 | 270 | | |
260 | 271 | | |
261 | 272 | | |
| |||
360 | 371 | | |
361 | 372 | | |
362 | 373 | | |
363 | | - | |
| 374 | + | |
364 | 375 | | |
365 | 376 | | |
366 | 377 | | |
367 | 378 | | |
368 | 379 | | |
369 | | - | |
| 380 | + | |
370 | 381 | | |
371 | 382 | | |
372 | 383 | | |
| |||
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
389 | 450 | | |
0 commit comments