Skip to content

Undefined behaviour crash on NaN/inf/-inf input #242

Description

@mjwillson

Sorry another UB bug:

I'm aware that zfp doesn't currently support round-tripping non-finite values, but it would be good if it didn't crash hard on NaN/inf/-inf input, in particular since client libraries like xarray / zarr will often pad data with NaNs, sometimes at a fairly low level in the library e.g. to achieve uniform chunk sizes before writing to zarr.

As in #241, with clang I get SIGILL crashes, and with UBSAN enabled it's attributed to, e.g.:

third_party/zfp/src/template/encodef.c:57:17: runtime error: nan is outside the range of representable values of type 'int'
    #0 0x55cf45e3edf7 in zfp_encode_block_float_4 third_party/zfp/src/template/encodef.c:98
    #1 0x55cf45e3f916 in zfp_encode_partial_block_strided_float_4 third_party/zfp/src/template/encode4.c:88:10
    #2 0x55cf45e480bc in compress_strided_float_4 third_party/zfp/src/template/compress.c:105:13
    #3 0x55cf45e464b2 in zfp_compress third_party/zfp/src/zfp.c:1116:3
...
SUMMARY: UndefinedBehaviorSanitizer: float-cast-overflow third_party/zfp/src/template/encodef.c:57:17

Assuming we want to allow some default conversion to happen silently, this can be worked around via -fno-strict-float-cast-overflow -fno-sanitize=float-cast-overflow, but I'm reluctant to enable these too widely in case it masks some other bug.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions