Skip to content

API contract violation in blosc2_compcode_to_compname on unknown compcode #700

@hgarrereyn

Description

@hgarrereyn

On code>=6, blosc2_compcode_to_compname returns a non-negative code but produces a null compname; according to the docs, -1 should be returned if the codec is not recognized. (not a serious issue but could be fixed easily)

I believe the issue is here:

c-blosc2/blosc/blosc2.c

Lines 293 to 294 in 4808890

else if (compcode >= BLOSC_LAST_CODEC)
code = compcode;

testcase.cpp

#include <cstdio>
#include <cstdlib>
extern "C" {
#include "blosc2.h"
}

int main() {
  // Pick a compcode that is not mapped/available in this build; 6 reproduces the issue here
  int code = 6;
  const char* compname = nullptr;
  int rc = blosc2_compcode_to_compname(code, &compname);
  // According to documentation, unknown/unsupported codes should return -1.
  // Observed behavior: rc == code (>=0) and compname == NULL for code 6.
  if (rc >= 0 && compname == nullptr) {
    // Demonstrate the contract violation
    fprintf(stderr, "contract violation: rc=%d, compname is NULL for code=%d\n", rc, code);
    abort();
  }
  return 0;
}

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