Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt parsing allows whitespace #44570

Open
Liozou opened this issue Mar 11, 2022 · 2 comments
Open

BigInt parsing allows whitespace #44570

Liozou opened this issue Mar 11, 2022 · 2 comments
Labels
domain:bignums BigInt and BigFloat kind:bug Indicates an unexpected problem or unintended behavior

Comments

@Liozou
Copy link
Member

Liozou commented Mar 11, 2022

julia> parse(Int, "100 10")
ERROR: ArgumentError: extra characters after whitespace in "100 10"

julia> parse(BigInt, "100 10")
10010

The second case is the oddity here, and it seems to originate from

err = GC.@preserve bstr MPZ.set_str!(z, pointer(bstr)+(i-firstindex(bstr)), base)

aka MPZ.set_str! does not follow Julia conventions for parsing numbers.

Originally posted by @Liozou in #44550 (comment)

Copy-pasted from #44550, discovered by @henriquebecker91

@oscardssmith oscardssmith added kind:bug Indicates an unexpected problem or unintended behavior domain:bignums BigInt and BigFloat labels Mar 11, 2022
@PallHaraldsson
Copy link
Contributor

PallHaraldsson commented Apr 10, 2024

I'm not sure how (easy it is) to fix this.

I like better to just drop BigInt support... move it too a package (making Julia smaller), yes a breaking change, or could still be loaded by default, conditional on an ENV var.

Not having it (be default or not) would get rid of a number of bugs like this one, and e.g. #52862

@quinnj
Copy link
Member

quinnj commented Apr 13, 2024

Note that Parsers.jl correctly errors in this case (though admittedly the error message mentioning "SUCCESS" is probably confusing along with the absence of a helpful error message):

julia> Parsers.parse(BigInt, "100 10")
ERROR: Parsers.Error (SUCCESS: OK ):
initial value parsing succeeded
attempted to parse BigInt from: "100 10"

Stacktrace:
 [1] parse
   @ ~/.julia/dev/Parsers/src/Parsers.jl:366 [inlined]
 [2] parse(::Type{BigInt}, buf::String)
   @ Parsers ~/.julia/dev/Parsers/src/Parsers.jl:362
 [3] top-level scope
   @ REPL[7]:1

@Liozou Liozou added domain:bignums BigInt and BigFloat and removed domain:bignums BigInt and BigFloat labels Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:bignums BigInt and BigFloat kind:bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants