Skip to content

Commit

Permalink
Fix case when float parsing, we failed to check eof before peeking
Browse files Browse the repository at this point in the history
Discovered while porting JSON.jl to Parsers 2.0. Unfortunately, the byte
peeking was under an `@inbounds`, so this usually wouldn't error unless
julia was run with `--check-bounds=yes` (which is the default when
running tests thankfully). Good candidate to backport for another 1.X
release.
  • Loading branch information
quinnj committed Jul 30, 2021
1 parent b463464 commit 3abe1ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/floats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ end
if negexp || b == UInt8('+')
pos += 1
incr!(source)
if eof(source, pos, len)
# it's an error to have a "dangling" '-' or '+', so input was something like "1.1e-"
code |= INVALID | EOF
@goto done
end
end
b = peekbyte(source, pos) - UInt8('0')
if b > 0x09
Expand Down
3 changes: 3 additions & 0 deletions test/floats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,7 @@ for _ = 1:1000
@test Base.parse(Float16, str) === Parsers.parse(Float16, str)
end

# discovered from JSON tests
@test Parsers.tryparse(Float64, "0e+") === nothing

end # @testset

0 comments on commit 3abe1ff

Please sign in to comment.