C strings are zero-terminated, and FreeImage_AcquireMemory isn't filling the buffer with non-zero bytes for `len()` to count. Even if it did, the assertion would fail as a C string can't have a length equal to the memory backing it without `len()` reading out of bounds.
Consider: var buffer = [byte('a'), byte('b'), 0, 0, 0] let cstr = cast[cstring](buffer[0].addr) doAssert cstr == "ab" doAssert cstr.len == 2 buffer[2] = byte('c') doAssert cstr.len == 3 Run