diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-06-17 01:35:54 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-06-17 01:35:54 +0200 |
| commit | 4f743e18aecda8f5ebf25b400452bd4c3409e4aa (patch) | |
| tree | 2112bef88bf2e003dfdb5bfb53c8fd8d3bfff50c /tests/tiny_model.h | |
| parent | e00becb643b3a99de16462b3a032717a93b983d9 (diff) | |
| download | ffwd-4f743e18aecda8f5ebf25b400452bd4c3409e4aa.tar.gz ffwd-4f743e18aecda8f5ebf25b400452bd4c3409e4aa.zip | |
tests: align fixture safetensors headers to 8 bytes
Diffstat (limited to 'tests/tiny_model.h')
| -rw-r--r-- | tests/tiny_model.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/tiny_model.h b/tests/tiny_model.h index 9aee665..54ad162 100644 --- a/tests/tiny_model.h +++ b/tests/tiny_model.h @@ -142,6 +142,18 @@ static int tm_write_safetensors_with_prefix_options(const char *path, if (hoff >= sizeof(header) - 1) return -1; + /* Pad the header with trailing spaces (valid JSON whitespace the parser + * skips) so the data section starts at a multiple of 8, exactly as the real + * safetensors serializer does. Without this the tensor data lands at an + * unaligned address and the loader's typed reads of it are UB - harmless on + * x86/arm64 but flagged by UBSan. Real model files are always aligned, so + * the fixtures must be too. */ + while ((8 + hoff) % 8 != 0) { + if (hoff >= sizeof(header)) + return -1; + header[hoff++] = ' '; + } + FILE *f = fopen(path, "wb"); if (!f) return -1; |
