Giter Club home page Giter Club logo

Comments (4)

Zentrik avatar Zentrik commented on August 20, 2024

Minimal reproducer: Parsers.xparse(BigFloat, Vector(codeunits("1")), 1, 1).

from parsers.jl.

Zentrik avatar Zentrik commented on August 20, 2024

Seems like we should also be using Cstring instead of Ptr as the second argument type to mpfr_strtofr.

from parsers.jl.

quinnj avatar quinnj commented on August 20, 2024

Hmmmm, interesting. Yes, I've definitely been assuming that a String or Vector{UInt8} input source will have the implicit nul terminator byte already there for us. Do you happen to know if this is a new failure? Like, since the Memory changes in Base? Doe we not see a Buffer Overflow in 1.9? That would suggest that maybe something with the new Memory changes is not the same as before.

Does just changing teh ccall argument from Ptr{UInt8} to Cstring fix the ASAN warning? I believe that should ensure the NUL terminator byte is present no matter the input, so if that fixes it, then that sounds like a fine change to me.

from parsers.jl.

Zentrik avatar Zentrik commented on August 20, 2024
for i in 1:10^7
    a = Vector(codeunits("123"))
    ptr = pointer(a)
    Base.unsafe_load(ptr)
    Base.unsafe_load(ptr+1)
    Base.unsafe_load(ptr+2)
    if Base.unsafe_load(ptr+3) != 0
        return i
    end
end

returns nothing on 1.10.2 whilst on 1.11-alpha2 it returns numbers below 100.
So perhaps something has changed, though I don't think it's guaranteed that a vector has a null terminator.

I'm having a little trouble with my asan build right now, but I see this on 1.11-alpha2 so I don't think just changing Ptr to Cstring is going to work.

julia> a = for i in 1:10^7
           a = Vector(codeunits("123"))
           ptr = pointer(a)
           Base.unsafe_load(ptr)
           Base.unsafe_load(ptr+1)
           Base.unsafe_load(ptr+2)
           if Base.unsafe_load(ptr+3) != 0
               return a
           end
       end
3-element Vector{UInt8}:
 0x31
 0x32
 0x33

julia> unsafe_string(Base.cconvert(Cstring, pointer(a)))
"123\xec\xff\x7f"

Oddly, there is no cconvert(Cstring, Vector) even though there is one for Cwstring.
I think a safe thing to do is to just copy into a String and then change Ptr to Cstring as well for good measure.

from parsers.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.