Skip to content

Blobs do not correctly account for alignment, corrupt data very easily #40

@rayegun

Description

@rayegun

I'm pretty sure this is very much unintended behavior, but if it's not it should be documented with a big warning sign next to it:

julia> struct Foo
           w::UInt64
           x::UInt64
           y::UInt32
           z::UInt64
       end

julia> b = Blobs.calloc(Foo)
Blob{Foo}(Ptr{Nothing}(0x0000000153725660), 0, 28) # NOTICE THE 28 HERE!

julia> sizeof(Foo)
32

julia> about(Foo)
Concrete (padded) DataType defined in Main, 32B
  Foo <: Any

Struct with 4 fields:
• w  UInt64
• x  UInt64
• y  UInt32
• z  UInt64

 ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
        8B              8B             4B+4B            8B       

# NOTE THAT THE 4B + 4B ABOVE INDICATES 4B OF PADDING!!

julia> b.z[] = rand(UInt64)
0xd9c412513e6fc134

julia> b.z[]
0xd9c412513e6fc134

julia> unsafe_load(b)
Foo(0x0000000000000000, 0x0000000000000000, 0x00000000, 0xd9c412513e6fc134)

julia> unsafe_load(pointer(b))
Foo(0x0000000000000000, 0x0000000000000000, 0x00000000, 0x00000000d9c41251)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions