|
| 1 | +use strict; |
| 2 | +use warnings; |
| 3 | + |
| 4 | +use FindBin; |
| 5 | +BEGIN { push @INC, $FindBin::Bin } |
| 6 | + |
| 7 | +use TestYAML (); |
| 8 | +use Test::More tests => 10; |
| 9 | +use YAML::Syck qw(Load); |
| 10 | + |
| 11 | +# GH #132 - base60 (sexagesimal) parsing safety |
| 12 | +# The parser walked a pointer before the start of the buffer when |
| 13 | +# processing the leftmost segment of a base-60 value. Verify that |
| 14 | +# int#base60 and float#base60 produce correct results and do not |
| 15 | +# crash or read out-of-bounds. |
| 16 | + |
| 17 | +$YAML::Syck::ImplicitTyping = 1; |
| 18 | + |
| 19 | +# --- int#base60 --- |
| 20 | +is( Load("--- 1:0:0\n"), 3600, "int base60: 1:0:0 = 3600" ); |
| 21 | +is( Load("--- 1:30:45\n"), 5445, "int base60: 1:30:45 = 5445" ); |
| 22 | +is( Load("--- 0:30\n"), 30, "int base60: 0:30 = 30" ); |
| 23 | +is( Load("--- 0:0\n"), 0, "int base60: 0:0 = 0" ); |
| 24 | + |
| 25 | +# --- float#base60 --- |
| 26 | +is( Load("--- 1:30:45.5\n"), 5445.5, "float base60: 1:30:45.5 = 5445.5" ); |
| 27 | +is( Load("--- 0:0.5\n"), 0.5, "float base60: 0:0.5 = 0.5" ); |
| 28 | + |
| 29 | +# --- edge cases: single-colon values --- |
| 30 | +is( Load("--- 59:59\n"), 3599, "int base60: 59:59 = 3599" ); |
| 31 | + |
| 32 | +# --- multi-segment --- |
| 33 | +is( Load("--- 1:2:3:4\n"), 223384, "int base60: 1:2:3:4 = 1*216000+2*3600+3*60+4" ); |
| 34 | + |
| 35 | +# --- negative base60 (parsed as string, not base60 - verify no crash) --- |
| 36 | +my $neg = Load("--- -1:30\n"); |
| 37 | +ok( defined $neg, "negative sexagesimal loads without crash" ); |
| 38 | + |
| 39 | +# --- large segment count (stress the loop) --- |
| 40 | +is( Load("--- 1:0:0:0\n"), 216000, "int base60: 1:0:0:0 = 216000" ); |
0 commit comments