#1985·stb

`stb_image_resize2` unaligned memory

Author: trilowyCreated Aug 6, 2026Updated Aug 10, 2026

Hi, I’m not sure this is really a bug as it happens when I use stb_image_resize2 with Zig instead of C, feel free to close it if not.

I have resized all kind of images with stbir_resize_uint8_linear and it works great, except for one image of size 1278x720 that I want to resize to 426x240.

From what I can understand, it seems that Zig is strict with alignment and detect at runtime that uint64_t is misaligned with horizontal->coefficients in float. Here is the full stacktrace:

thread 14362 panic: store of misaligned address 0x7e44db36550c for type 'stbir_uint64' (aka 'unsigned long'), which requires 8 byte alignment
./stb_image_resize2.h:3811:11: 0x121f139 in stbir__pack_coefficients (stb_image_resize2.c)
          STBIR_MOVE_2( pc+8, coeffs+8 );
          ^
./stb_image_resize2.h:7333:39: 0x120d0a3 in stbir__alloc_internal_mem_and_build_samplers (stb_image_resize2.c)
      horizontal->coefficient_width = stbir__pack_coefficients(horizontal->num_contributors, horizontal->contributors, horizontal->coefficients, horizontal->coefficient_width, horizontal->extent_info.widest, info->scanline_extents.conservative.n0, info->scanline_extents.conservative.n1 );
                                      ^
./stb_image_resize2.h:7927:14: 0x11a278f in stbir__perform_build (stb_image_resize2.c)
  out_info = stbir__alloc_internal_mem_and_build_samplers( &horizontal, &vertical, &conservative, resize->input_pixel_layout_public, resize->output_pixel_layout_public, splits, new_output_subx, new_output_suby, resize->fast_alpha, resize->user_data STBIR_ONLY_PROFILE_BUILD_SET_INFO );
             ^
./stb_image_resize2.h:7967:12: 0x11a1234 in stbir_build_samplers_with_splits (stb_image_resize2.c)
    return stbir__perform_build( resize, splits );
           ^
./stb_image_resize2.h:7977:10: 0x11a2999 in stbir_build_samplers (stb_image_resize2.c)
  return stbir_build_samplers_with_splits( resize, 1 );
         ^
./stb_image_resize2.h:7994:11: 0x11a2c60 in stbir_resize_extended (stb_image_resize2.c)
    if ( !stbir_build_samplers( resize ) )
          ^
./stb_image_resize2.h:8108:9: 0x11a3c89 in stbir_quick_resize_helper (stb_image_resize2.c)
  if ( !stbir_resize_extended( &resize ) )
        ^
./stb_image_resize2.h:8124:28: 0x11a3622 in stbir_resize_uint8_linear (stb_image_resize2.c)
  return (unsigned char *) stbir_quick_resize_helper( input_pixels , input_w , input_h, input_stride_in_bytes, 
                           ^
/home/trilowy/workspace/stb_image_resize2_bug/main.zig:26:47: 0x113feee in main (main.zig)
    const status = c.stbir_resize_uint8_linear(
                                              ^
/nix/store/pzszij26l29c9dcr6wxalc5jxd31w4sr-zig-0.15.2/lib/zig/std/start.zig:627:37: 0x1140591 in main (std.zig)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7e44db02b284 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x7e44db02b284` was not available, trace may be incomplete

???:?:?: 0x7e44db02b337 in ??? (libc.so.6)
???:?:?: 0x1176d84 in ??? (???)
[1]    14362 abort (core dumped)  zig run main.zig stb_image_resize2.c -I. -lc

I also made a reproducible example stb_image_resize2_bug.zip in case you need it, I launch it with Zig 0.15.2 on Linux x86_64 with this command line:

zig run main.zig stb_image_resize2.c -I. -lc

I did not include the image as it is not relevant, just an array of bytes with the same length can reproduce the bug I’m having.

FYI, I have tested the version 1 of stb_image_resize and it has not that problem.

Thank you for your time and for the great lib :)