Skip to content

File::set_len uses an unsafe cast on Unix #63326

Closed
bytecodealliance/wasmtime
#2164
@marmistrz

Description

@marmistrz

Precisely, size as off64_t. The conversion occurs here
On my system off64_t is i64. This means that the number will overflow if larger than i64::max_value() and become negative. In such case, ftruncate will return an EINVAL: (from man ftruncate:

       EINVAL The argument length is negative or larger than the maximum file size.

Should we manually return an error should an overflow occur or is the EINVAL returned by ftruncate the intended behavior? I would return an io::ErrorKind::InvalidInput with the payload indicating that an overflow occured (or even just TryFromIntError(()) which try_into returns)

This issue was noticed while discussing CraneStation/wasi-common#47.
cc @alexcrichton

I will implement the fix once we've decided what kind of behavior we want.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions