Commit graph

34781 commits

Author SHA1 Message Date
Andrew Kelley
504c85a626 Sema: allow coercion of generic function pointer
to runtime function pointer when comptime-known.
2025-09-10 01:47:51 -07:00
LukaTD
0b75a2a1b1
langref: added missing newlines to destructuring tuples example
langref: added missing newlines to destructuring tuples example
2025-09-10 02:31:20 +00:00
Andrew Kelley
f63cd9194c
Merge pull request #25191 from ziglang/fix-linker-undef-memory
fix linker writing undefined memory to output file
2025-09-09 00:04:37 -07:00
Andrew Kelley
3071ba4272
Merge pull request #25190 from blblack/netcalls
Add missing posix wrappers for socketpair() and recvmsg()
2025-09-08 20:47:54 -07:00
Andrew Kelley
877d6df8f7 fix linker code writing undefined memory to the output file
missing `extern` on a struct.

but also all these instances that call pwriteAll with a `@ptrCast` are
endianness bugs.

this should be changed to use File.Writer and call writeSliceEndian
instead.

this commit fixes one immediate problem but does not fix everything.
2025-09-08 18:23:01 -07:00
Andrew Kelley
eac2bbfec9 std.Io.Writer.writeSliceEndian: add compile error
check when an auto-layout struct is attempted to be memory reinterpreted
and written out. it would be writing undefined memory
2025-09-08 18:18:27 -07:00
Frank Denis
1872c85ac2 std.crypto.ed25519: support cofactorless verification
Add verifyStrict() functions for cofactorless verification.

Also:

- Support messages < 64 characters in the test vectors
- Allow mulDoubleBasePublic to return the identity as a regular
value. There are valid use cases for this.
2025-09-08 14:25:57 -07:00
Igor Anić
c41b9d7508
ECDSA signature der encoding should produce smallest number of octets (#25177)
I noticed this by stress testing my tls server implementation. From time to time curl (and other tools: ab, vegeta) will report invalid signature. I trace the problem to the way how std lib is encoding raw signature into der format. Using raw signature I got in some cases different encoding using std and openssl. Std is not producing minimal der when signature `r` or `s` integers has leading zero(es).

Here is an example to illustrate difference. Notice leading 00 in `s`
integer which is removed in openssl encoding but not in std encoding.

```Zig
const std = @import("std");

test "ecdsa signature to der" {
    // raw signature r and s bytes
    const raw = hexToBytes(
        \\ 49  63  0c  94  95  2e  ff  4b  02  bf  35  c4  97  9e  a7  24
        \\ 20  dc  94  de  aa  1b  17  ff  e1  49  25  3e  34  ef  e8  d0
        \\ c4  43  aa  7b  a9  f3  9c  b9  f8  72  7d  d7  0c  9a  13  1e
        \\
        \\ 00  56  85  43  d3  d4  05  62  a1  1d  d8  a1  45  44  b5  dd
        \\ 62  9f  d1  e0  ab  f1  cd  4a  85  d0  1f  5d  11  d9  f8  89
        \\ 89  d4  59  0c  b0  6e  ea  3c  19  6a  f7  0b  1a  4a  ce  f1
    );
    // encoded by openssl
    const expected = hexToBytes(
        \\ 30  63  02  30
        \\ 49  63  0c  94  95  2e  ff  4b  02  bf  35  c4  97  9e  a7  24
        \\ 20  dc  94  de  aa  1b  17  ff  e1  49  25  3e  34  ef  e8  d0
        \\ c4  43  aa  7b  a9  f3  9c  b9  f8  72  7d  d7  0c  9a  13  1e
        \\
        \\ 02  2f
        \\ 56  85  43  d3  d4  05  62  a1  1d  d8  a1  45  44  b5  dd
        \\ 62  9f  d1  e0  ab  f1  cd  4a  85  d0  1f  5d  11  d9  f8  89
        \\ 89  d4  59  0c  b0  6e  ea  3c  19  6a  f7  0b  1a  4a  ce  f1
    );
    // encoded by std
    const actual = hexToBytes(
        \\ 30  64  02  30
        \\ 49  63  0c  94  95  2e  ff  4b  02  bf  35  c4  97  9e  a7  24
        \\ 20  dc  94  de  aa  1b  17  ff  e1  49  25  3e  34  ef  e8  d0
        \\ c4  43  aa  7b  a9  f3  9c  b9  f8  72  7d  d7  0c  9a  13  1e
        \\
        \\ 02  30
        \\ 00  56  85  43  d3  d4  05  62  a1  1d  d8  a1  45  44  b5  dd
        \\ 62  9f  d1  e0  ab  f1  cd  4a  85  d0  1f  5d  11  d9  f8  89
        \\ 89  d4  59  0c  b0  6e  ea  3c  19  6a  f7  0b  1a  4a  ce  f1
    );
    _ = actual;

    const Ecdsa = std.crypto.sign.ecdsa.EcdsaP384Sha384;
    const sig = Ecdsa.Signature.fromBytes(raw);
    var buf: [Ecdsa.Signature.der_encoded_length_max]u8 = undefined;
    const encoded = sig.toDer(&buf);

    try std.testing.expectEqualSlices(u8, &expected, encoded);
}

pub fn hexToBytes(comptime hex: []const u8) [removeNonHex(hex).len / 2]u8 {
    @setEvalBranchQuota(1000 * 100);
    const hex2 = comptime removeNonHex(hex);
    comptime var res: [hex2.len / 2]u8 = undefined;
    _ = comptime std.fmt.hexToBytes(&res, hex2) catch unreachable;
    return res;
}
fn removeNonHex(comptime hex: []const u8) []const u8 {
    @setEvalBranchQuota(1000 * 100);
    var res: [hex.len]u8 = undefined;
    var i: usize = 0;
    for (hex) |c| {
        if (std.ascii.isHex(c)) {
            res[i] = c;
            i += 1;
        }
    }
    return res[0..i];
}
```

Trimming leading zeroes from signature integers fixes encoding.
2025-09-08 22:53:03 +02:00
Brandon Black
c4c6c01cc5 recvmsg: posix wrapper, void on windows
Also, added EPIPE to recvfrom() error set (it's a documented error
for unix and tcp sockets, at least), which recvmsg() largely
shares.  Windows has an odd, callback-based form of recvmsg() that
doesn't fit the normal interface here.
2025-09-08 14:45:51 -05:00
Brandon Black
79313d844f socketpair: posix wrapper, void on windows
socketpair is something like a pipe2() for sockets, and generally
only works for AF_UNIX sockets for most platforms.  Winsock2
explicitly does not support this call, even though it does have
AF_UNIX sockets.
2025-09-08 14:45:51 -05:00
Andrew Kelley
05cff8a558
Merge pull request #25186 from ziglang/vector-memory-coercion
frontend: vectors and arrays no longer support in-memory coercion
2025-09-08 03:59:38 -07:00
Andrew Kelley
7666d5fc26 add compile error test case 2025-09-07 23:03:06 -07:00
Andrew Kelley
dca4c302dd std.mem.indexOfSentinel: eliminate unnecessary @ptrCast
it was always unnecessary but now it's illegal
2025-09-07 20:23:36 -07:00
Andrew Kelley
2d9df0bb1a behavior tests: remove one dependency on std lib 2025-09-07 20:23:05 -07:00
Andrew Kelley
04bd30f021 std.debug.assertAligned: support const pointers 2025-09-07 20:22:38 -07:00
Andrew Kelley
5701617b27 wasm backend: disable failing behavior tests 2025-09-07 20:11:37 -07:00
Andrew Kelley
6673b47685 frontend: vectors and arrays no longer support in-memory coercion
closes #25172
2025-09-07 17:29:36 -07:00
Andrew Kelley
426d65d700 Compilation: fix buildGlibcSharedObjects error handling
Oops, this was supposed to be only a temporary troubleshooting patch.
2025-09-06 19:32:27 -07:00
baltevl
34409635ad std.http.Client.Connection: make host() public
Closes #25153
2025-09-06 19:23:27 -07:00
Frank Denis
02396f8d5c
Document std.mem.* functions (#25168)
* Document std.mem.* functions

Functions in std.mem are essential for virtually all applications,
yet many of them lacked documentation.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-09-06 18:55:57 -07:00
kcbanner
cc6d9fdbf4 webui: fixup build errors in fuzz / time_report 2025-09-06 18:51:26 -07:00
Andrew Kelley
4c01275664
Merge pull request #25163 from ziglang/packed-union-unused
forbid unused bits in packed unions
2025-09-06 12:08:31 -07:00
Andrew Kelley
91b3769b03 langref: update "Choosing an Allocator" section
and delete "Implementing an Allocator" section because it is out of
scope.
2025-09-06 11:51:27 -07:00
Andrew Kelley
4f7aecd348 disable failing behavior test on stage2_aarch64 2025-09-05 23:47:56 -07:00
rpkak
1a5cf072a8 remove ResponseStorage
unused since 5ce8e9325b
2025-09-05 22:50:14 -07:00
Andrew Kelley
5dc5bf6a6b add compile error test case for new error 2025-09-05 19:55:45 -07:00
Andrew Kelley
8c631ebfee langref: update for new packed union rules 2025-09-05 19:45:18 -07:00
Andrew Kelley
b074299124 std: update for new packed union rules 2025-09-05 19:45:07 -07:00
Andrew Kelley
b9a63433b7 behavior tests: update for new requirement
packed union fields must all have matching bit sizes
2025-09-05 19:44:54 -07:00
Andrew Kelley
52c6d7a929 Sema: forbid packed unions with mismatched field bit sizes 2025-09-05 18:45:24 -07:00
Andrew Kelley
1d764c1fdf Revert "Merge pull request #24905 from gooncreeper/file-reader-buffered"
This reverts commit ac42eaaadd, reversing
changes made to 9fa2394f8c.

I would like a chance to review this, please. I already spotted some
issues.
2025-09-05 11:26:38 -07:00
Isaac Freund
ac42eaaadd
Merge pull request #24905 from gooncreeper/file-reader-buffered
Fix Io.Writer sendFile bugs with buffered reader contents
2025-09-05 16:28:08 +02:00
Alex Rønne Petersen
9fa2394f8c
Merge pull request #25147 from lunagl/reenable-tests
Reenable failing vector tests
2025-09-05 04:35:11 +02:00
Andrew Kelley
f78f70dbd8 std.fs.File.Writer: break up seekTo
- introduce seekToUnbuffered which asserts no buffered data and does not
  have WriteFailed in the error set
- remove WriteFailed from SeekError
- make seekTo based on calling flush and then seekToUnbuffered
- revert the change to reset seek_err since the error sets are
  compatible again
2025-09-04 16:05:55 -07:00
Kendall Condon
d26b532647 sendFileAll: use stream instead of sendFileReading
This is a simpler implementation and allows file_reader to do more
optimal streaming.
2025-09-04 17:26:52 -04:00
Kendall Condon
58dda3b10b fix sendFile implementations bypassing interface buffer
Also removes `File.Reader.read` since it is otherwise unused and is a
footgun.
2025-09-04 17:26:49 -04:00
Kendall Condon
7687b916fd File.Writer.sendFile: properly update reader pos
seekBy affects the reader's physical position, not its logical
position.
2025-09-04 16:38:50 -04:00
Luna Schwalbe
63ab0c0302
Reenable vector tests for armeb/thumbeb
https://github.com/ziglang/zig/issues/22060 has been fixed by upstream.
2025-09-04 16:23:18 +02:00
Luna Schwalbe
a9f06d16fd
Reenable std.fmt.test.vector for riscv64
The vector codegen issue as described in
https://github.com/ziglang/zig/issues/4486 has been fixed upstream.
2025-09-04 16:15:00 +02:00
Alex Rønne Petersen
d94e061ade
Merge pull request #25137 from alexrp/elf-gabi-4.3
ELF updates for gABI 4.3
2025-09-04 10:58:28 +02:00
Luna Schwalbe
9649ff37ef BitcodeReader: parse blockinfo inside block
Call start/endBlock before/after `parseBlockInfoBlock` in order to not
use the current block context, which is wrong and leads to e.g. incorrect
abbrevlen being used.
2025-09-03 21:47:32 -07:00
whatisaphone
ae518dcb41 Add allocator that always fails 2025-09-03 21:46:01 -07:00
Brandon Black
76c62e509b Fix cmsghdr struct for the *nixes
Previously we had a single definition of std.c.cmsghdr for all
libc-linking platforms which aliased from the Solaris definition,
a superfluous matching one in std.os.dragonfly, and no others.

The existing definition from std.c didn't actually work for Linux,
as Linux's "len" field is usize in the kernel's definition.

Emscripten follows the Linux model of course (but uses the
binary-compatible musl definition, which has an endian-sensitive
padding scheme to make the len type "socklen_t" even though the
kernel uses a usize, which is fair).

This unifies and documents all the known *nix-ish cases (I'm not
sure if wasi or windows really has cmsghdr support? Could be added
later, void for now), such that c.cmsghdr and posix.system.cmsghdr
should work correctly for all the known cases here, libc or
otherwise.
2025-09-03 21:45:03 -07:00
Josh GM Walker
b1189ab038
fix: std.fs.File.Writer.seekTo does not flush (#25135)
* add failing test case
* perform flush and allow error
* dont over constrain flush error
* reset seek error during conversion
2025-09-03 21:43:47 -07:00
Alex Rønne Petersen
32a34b64ca
Merge pull request #25125 from alexrp/loongarch-qemu-crashes
`std.debug`: disable stack traces on loongarch
2025-09-04 04:06:47 +02:00
Alex Rønne Petersen
210b764c03
link.Elf: truncate st_other to u3 before converting to std.elf.STV
See 6b6e336e07 for context, but note that in
gABI 4.3, 3 bits are reserved for the visibility, up from the previous 2.
2025-09-04 01:16:27 +02:00
Alex Rønne Petersen
a82f446d91
std.elf: change STV enum from u2 to u3
In gABI 4.3, st_other was changed such that the lower 3 bits are reserved for
the visibility, up from the previous 2 bits.
2025-09-04 01:16:23 +02:00
Alex Rønne Petersen
9e076d8c75
std.elf: add new EM values from gABI 4.3 2025-09-04 01:16:22 +02:00
Alex Rønne Petersen
1ca446abc3
std.elf: document which EM values are not assigned in gABI 2025-09-04 01:13:59 +02:00
Alex Rønne Petersen
1c090d3d67
std.elf: document which OSABI values are not assigned in gABI 2025-09-04 01:13:59 +02:00