From c96cd1adc5b8049513ce2ccdfb32f6e0843cc16f Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 20 Feb 2017 07:38:55 +0100 Subject: [PATCH] fix ChunkIndex.__contains__ assertion for big-endian archs also: add some missing assertion messages severity: - no issue on little-endian platforms (== most, including x86/x64) - harmless even on big-endian as long as refcount is below 0xfffbffff, which is very likely always the case in practice anyway. --- borg/hashindex.pyx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/borg/hashindex.pyx b/borg/hashindex.pyx index 1b0d07c2f..8e0a833a8 100644 --- a/borg/hashindex.pyx +++ b/borg/hashindex.pyx @@ -216,7 +216,7 @@ cdef class ChunkIndex(IndexBase): if not data: raise KeyError(key) cdef uint32_t refcount = _le32toh(data[0]) - assert refcount <= _MAX_VALUE + assert refcount <= _MAX_VALUE, "invalid reference count" return refcount, _le32toh(data[1]), _le32toh(data[2]) def __setitem__(self, key, value): @@ -234,7 +234,7 @@ cdef class ChunkIndex(IndexBase): assert len(key) == self.key_size data = hashindex_get(self.index, key) if data != NULL: - assert data[0] <= _MAX_VALUE + assert _le32toh(data[0]) <= _MAX_VALUE, "invalid reference count" return data != NULL def incref(self, key): @@ -312,8 +312,8 @@ cdef class ChunkIndex(IndexBase): if values: refcount1 = _le32toh(values[0]) refcount2 = _le32toh(data[0]) - assert refcount1 <= _MAX_VALUE - assert refcount2 <= _MAX_VALUE + assert refcount1 <= _MAX_VALUE, "invalid reference count" + assert refcount2 <= _MAX_VALUE, "invalid reference count" result64 = refcount1 + refcount2 values[0] = _htole32(min(result64, _MAX_VALUE)) else: