| 466 | ) |
| 467 | |
| 468 | func allowedAliasRatio(decodeCount int) float64 { |
| 469 | switch { |
| 470 | case decodeCount <= alias_ratio_range_low: |
| 471 | // allow 99% to come from alias expansion for small-to-medium documents |
| 472 | return 0.99 |
| 473 | case decodeCount >= alias_ratio_range_high: |
| 474 | // allow 10% to come from alias expansion for very large documents |
| 475 | return 0.10 |
| 476 | default: |
| 477 | // scale smoothly from 99% down to 10% over the range. |
| 478 | // this maps to 396,000 - 400,000 allowed alias-driven decodes over the range. |
| 479 | // 400,000 decode operations is ~100MB of allocations in worst-case scenarios (single-item maps). |
| 480 | return 0.99 - 0.89*(float64(decodeCount-alias_ratio_range_low)/alias_ratio_range) |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | func (d *decoder) unmarshal(n *Node, out reflect.Value) (good bool) { |
| 485 | d.decodeCount++ |