Skip to content

use-after-free occurring in std.math.big.Rational on 32-bit architectures #6167

@andrewrk

Description

@andrewrk

Repro with i386-linux:

$ ./zig test ../lib/std/math/big/rational.zig --test-filter "setFloatString"  -target i386-native
Test [1/1] test "big.rational setFloatString"...error: TargetTooSmall
/home/andy/Downloads/zig/lib/std/heap/general_purpose_allocator.zig:561:13: 0x40481e in std.heap.general_purpose_allocator.GeneralPurposeAllocator((struct std.heap.general_purpose_allocator.Config constant)).resize (test)
            return error.OutOfMemory;
            ^
/home/andy/Downloads/zig/lib/std/heap/general_purpose_allocator.zig:561:13: 0x40481e in std.heap.general_purpose_allocator.GeneralPurposeAllocator((struct std.heap.general_purpose_allocator.Config constant)).resize (test)
            return error.OutOfMemory;
            ^
/home/andy/Downloads/zig/lib/std/heap/general_purpose_allocator.zig:561:13: 0x40481e in std.heap.general_purpose_allocator.GeneralPurposeAllocator((struct std.heap.general_purpose_allocator.Config constant)).resize (test)
            return error.OutOfMemory;
            ^
/home/andy/Downloads/zig/lib/std/heap/general_purpose_allocator.zig:561:13: 0x40481e in std.heap.general_purpose_allocator.GeneralPurposeAllocator((struct std.heap.general_purpose_allocator.Config constant)).resize (test)
            return error.OutOfMemory;
            ^
/home/andy/Downloads/zig/lib/std/heap/general_purpose_allocator.zig:561:13: 0x40481e in std.heap.general_purpose_allocator.GeneralPurposeAllocator((struct std.heap.general_purpose_allocator.Config constant)).resize (test)
            return error.OutOfMemory;
            ^
/home/andy/Downloads/zig/lib/std/heap/general_purpose_allocator.zig:561:13: 0x40481e in std.heap.general_purpose_allocator.GeneralPurposeAllocator((struct std.heap.general_purpose_allocator.Config constant)).resize (test)
            return error.OutOfMemory;
            ^
/home/andy/Downloads/zig/lib/std/math/big/int.zig:1025:21: 0x40e8eb in std.math.big.int.Const.to (test)
                    return error.TargetTooSmall;
                    ^
/home/andy/Downloads/zig/lib/std/math/big/int.zig:1518:9: 0x405b44 in std.math.big.int.Managed.to (test)
        return self.toConst().to(T);
        ^
/home/andy/Downloads/zig/lib/std/math/big/rational.zig:574:21: 0x404dbb in test "big.rational setFloatString" (test)
    testing.expect((try a.p.to(u128)) == 7214159312071241458852455252781510353);
                    ^
/home/andy/Downloads/zig/lib/std/special/test_runner.zig:75:17: 0x43e7d2 in std.special.main (test)
                return err;
                ^

Also repros with wasm32-wasi.

This was uncovered by 6fb105f.

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingImplementing this issue could cause existing code to no longer compile or have different behavior.bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions