Skip to content

unsafe_wrap with incorrect bounds is UB #36

@vtjnash

Description

@vtjnash

LLVM could theoretically detect that this array iteration bound is invalid, and generate illegal loads here, since the information passed to unsafe_wrap is not valid (the max possible legal size here is also typemax(Int)/sizeof(Int), though that still would trigger UB)

function listallplots(nplots=Int(maxintfloat()))
. Using maxintfloat is even more of an issue here because (a) Float is not involved anywhere (b) On 32-bit, that would correspond to exactly typemax, but that is not larger than the representable maximum value that is legal.

It is not particularly clear why it would decide to try to vectorize this code, since unsafe_string is already expensive there, but formally this array size could trigger UB since it aliases other memory and points to memory that is undefined.

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