-
-
Notifications
You must be signed in to change notification settings - Fork 94
Description
Describe the bug
When building and running the test suite using Zig, several tests trip a not-null assertion in memcpy.
I only saw this happen on the Ubuntu CI runner, and not on my laptop which is using the musl libc based Chimera Linux.
To Reproduce
Download Zig 0.15.2.
git clone https://github.com/allyourcodebase/c-blosc2 zig-c-blosc2
cd zig-c-blosc2
git checkout enable-memcpy-from-null-tests
zig build test
Expected behavior
The tests should not panic.
This seems like it would make sense to fix in the library, however it could potentially be fixed by disabling some runtime safety checks that Zig adds by default.
Logs
Sample stack trace:
+- run exe test_b2nd_roundtrip failure
thread 29925 panic: null pointer passed as argument 2, which is declared to never be null
/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/frame.c:1058:5: 0x15fd488 in frame_from_schunk (/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/frame.c)
memcpy(frame->cframe + h2len + cbytes, off_chunk, off_cbytes);
^
/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/schunk.c:189:25: 0x15dad5a in blosc2_schunk_new (/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/schunk.c)
int64_t frame_len = frame_from_schunk(schunk, frame);
^
/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/b2nd.c:307:23: 0x16266f2 in array_new (/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/b2nd.c)
blosc2_schunk *sc = blosc2_schunk_new(ctx->b2_storage);
^
/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/b2nd.c:381:3: 0x1627c51 in b2nd_empty (/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/b2nd.c)
BLOSC_ERROR(array_new(ctx, BLOSC2_SPECIAL_ZERO, array));
^
/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/b2nd.c:570:3: 0x162a7ac in b2nd_from_cbuffer (/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/blosc/b2nd.c)
BLOSC_ERROR(b2nd_empty(ctx, array));
^
/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/tests/b2nd/test_b2nd_roundtrip.c:52:3: 0x1053198 in roundtrip_test (/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/tests/b2nd/test_b2nd_roundtrip.c)
B2ND_TEST_ASSERT(b2nd_from_cbuffer(ctx, &src, buffer, buffersize));
^
/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/tests/b2nd/cutest.h:183:14: 0x1052919 in _cutest_run (/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/tests/b2nd/test_b2nd_roundtrip.c)
int rc = test();
^
/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/tests/b2nd/test_b2nd_roundtrip.c:77:3: 0x10539eb in main (/home/runner/.cache/zig/p/N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv/tests/b2nd/test_b2nd_roundtrip.c)
CUTEST_TEST_RUN(roundtrip);
^
???:?:?: 0x7f4cb822a1c9 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7f4cb822a1c9` was not available, trace may be incomplete
???:?:?: 0x7f4cb822a28a in ??? (libc.so.6)
???:?:?: 0x1050824 in ??? (???)
error: the following command terminated with signal 6 (expected exited with code 0):
cd /home/runner/.cache/zig/o/8f2034b2e57f86351d83d4dac638ab7f/test_b2nd_roundtrip && /home/runner/.cache/zig/o/154a35acca669314a1626b1a08e9eb13/test_b2nd_roundtrip
And here's the summary of which tests failed:
Build Summary: 143/167 steps succeeded; 23 failed
test transitive failure
+- run exe test_copy failure
+- run exe test_delete_chunk failure
+- run exe test_fill_special failure
+- run exe test_frame failure
+- run exe test_frame_get_offsets failure
+- run exe test_frame_offset failure
+- run exe test_get_slice_buffer failure
+- run exe test_get_slice_nchunks failure
+- run exe test_insert_chunk failure
+- run exe test_reorder_offsets failure
+- run exe test_schunk_frame failure
+- run exe test_schunk_header failure
+- run exe test_set_slice_buffer failure
+- run exe test_update_chunk failure
+- run exe test_zero_runlen failure
+- run exe test_b2nd_append failure
+- run exe test_b2nd_concatenate failure
+- run exe test_b2nd_copy failure
+- run exe test_b2nd_delete failure
+- run exe test_b2nd_insert failure
+- run exe test_b2nd_open_offset failure
+- run exe test_b2nd_resize failure
+- run exe test_b2nd_roundtrip failure
System information:
- OS: 24.04.3
- Compiler: Used Zig 0.15.2, which relies on LLVM 0.20.x under the hood.
- Version: 2.21.3
Additional context
This was based on a port of the build script from cmake to Zig. The Zig build script has many missing features and may be wrong, in which case I apologize for generating a spurious bug report.
Edit:
If you want to test fixes, you can modify the build.zig.zon to point it to a local path. For instance, I am using the following patch to test if changes to c-blosc2 work:
diff --git a/build.zig.zon b/build.zig.zon
index 2854c3885f..e9427d3bb4 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -3,8 +3,7 @@
.version = "2.21.3",
.dependencies = .{
.c_blosc2 = .{
- .url = "git+https://github.com/Blosc/c-blosc2?ref=v2.21.3#0c853a639ba97997e33e29db9eed202459ebc6f0",
- .hash = "N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv",
+ .path = "../../../Downloads/software/blosc/c-blosc2",
},
.lz4 = .{
.url = "git+https://github.com/allyourcodebase/lz4.git#873969ee73aecb3c35203feaf0b5727b9d02b864",