summaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/util/compress.h
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src/vespa/vespalib/util/compress.h')
-rw-r--r--vespalib/src/vespa/vespalib/util/compress.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/compress.h b/vespalib/src/vespa/vespalib/util/compress.h
index 5cf2814f3ea..66234da0e32 100644
--- a/vespalib/src/vespa/vespalib/util/compress.h
+++ b/vespalib/src/vespa/vespalib/util/compress.h
@@ -105,6 +105,32 @@ public:
}
return numbytes;
}
+
+ static bool check_decompress_space(const void* srcv, size_t len) {
+ if (len == 0u) {
+ return false;
+ }
+ const uint8_t * src = static_cast<const uint8_t *>(srcv);
+ const uint8_t c = src[0];
+ if ((c & 0x40) != 0) {
+ return (((c & 0x20) != 0) ? (len >= 4u) : (len >= 2u));
+ } else {
+ return true;
+ }
+ }
+
+ static bool check_decompress_positive_space(const void* srcv, size_t len) {
+ if (len == 0u) {
+ return false;
+ }
+ const uint8_t * src = static_cast<const uint8_t *>(srcv);
+ const uint8_t c = src[0];
+ if ((c & 0x80) != 0) {
+ return (((c & 0x40) != 0) ? (len >= 4u) : (len >= 2u));
+ } else {
+ return true;
+ }
+ }
private:
[[ noreturn ]] static void throw_too_big(int64_t n);
[[ noreturn ]] static void throw_too_big(uint64_t n);