Files
Martin Vogel 7814dacf15 fix: size the compress path with size_t and prune the cache from the walk
Two loose ends from the bounds work.

The decompression side already took size_t so a >2 GiB capacity could not wrap
through int, but compression still took int for both the source length and the
destination capacity, and the artifact export cast a size_t database size down
to reach it. A database past 2 GiB would have handed the encoder a negative
length. Both lengths and the bound helper are size_t now, and the function
returns int64_t like its decompressing counterpart.

The discovery walk now prunes the cache directory by absolute path. A custom
CBM_CACHE_DIR may sit inside a repository — tests do it routinely — and walking
into it pulls every other project's graph database into this project's file
list. This is the narrow form of a concern that was briefly implemented as
refusing any root that contained the cache; refusing a whole root was too blunt,
and not walking the cache is what the concern actually asks for.

The test fails without the prune: a .go file planted under the cache is
otherwise discovered, and "cache" is not in the built-in skip list, so the
assertion is not vacuous.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2026-08-06 16:06:43 +02:00

37 lines
971 B
C

// zstd_store.c — Thin C wrappers around Zstandard.
#include "vendored/zstd/zstd.h"
#include "zstd_store.h"
#include <stddef.h>
#include <stdint.h>
int64_t cbm_zstd_compress(const char *src, size_t srcLen, char *dst, size_t dstCap, int level) {
size_t rc = ZSTD_compress(dst, dstCap, src, srcLen, level);
if (ZSTD_isError(rc)) {
return 0;
}
return (int64_t)rc;
}
int64_t cbm_zstd_decompress(const char *src, size_t srcLen, char *dst, size_t dstCap) {
size_t rc = ZSTD_decompress(dst, dstCap, src, srcLen);
if (ZSTD_isError(rc)) {
return 0;
}
return (int64_t)rc;
}
size_t cbm_zstd_frame_content_size(const char *src, size_t srcLen) {
unsigned long long n = ZSTD_getFrameContentSize(src, srcLen);
if (n == ZSTD_CONTENTSIZE_UNKNOWN || n == ZSTD_CONTENTSIZE_ERROR) {
return 0;
}
return (size_t)n;
}
size_t cbm_zstd_compress_bound(size_t inputSize) {
return ZSTD_compressBound(inputSize);
}