Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/borg/hashindex.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class ChunkIndex(HTProxyMixin, MutableMapping):
flags = self.F_USED
else:
flags = v.flags | self.F_USED
assert v.size == 0 or v.size == size
if v.size != 0 and v.size != size:
raise ValueError(f"Invalid size: expected 0 or {size}, got {v.size}")
self[key] = ChunkIndexEntry(flags=flags, size=size)

def __getitem__(self, key):
Expand Down Expand Up @@ -217,8 +218,10 @@ class NSIndex1(HTProxyMixin, MutableMapping):
magic, entries, buckets, ksize, vsize = struct.unpack(self.HEADER_FMT, header_bytes)
if magic != self.MAGIC:
raise ValueError(f"Invalid file, magic {self.MAGIC.decode()} not found.")
assert ksize == self.KEY_SIZE, "invalid key size"
assert vsize == self.VALUE_SIZE, "invalid value size"
if ksize != self.KEY_SIZE:
raise ValueError("Invalid key size")
if vsize != self.VALUE_SIZE:
raise ValueError("Invalid value size")
buckets_size = buckets * (ksize + vsize)
current_pos = fd.tell()
end_of_file = fd.seek(0, os.SEEK_END)
Expand All @@ -230,4 +233,5 @@ class NSIndex1(HTProxyMixin, MutableMapping):
value = fd.read(vsize)
self.ht._set_raw(key, value)
pos = fd.tell()
assert pos == end_of_file
if pos != end_of_file:
raise ValueError(f"Expected pos ({pos}) to be at end_of_file ({end_of_file})")
15 changes: 10 additions & 5 deletions src/borg/platform/posix.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ def process_alive(host, pid, thread):
from . import local_pid_alive
from . import hostid

assert isinstance(host, str)
assert isinstance(hostid, str)
assert isinstance(pid, int)
assert isinstance(thread, int)
if not isinstance(host, str):
raise TypeError("host must be a string")
if not isinstance(hostid, str):
raise TypeError("hostid must be a string")
if not isinstance(pid, int):
raise TypeError("pid must be an integer")
if not isinstance(thread, int):
raise TypeError("thread must be an integer")

if host != hostid:
return True
Expand Down Expand Up @@ -116,7 +120,8 @@ def group2gid(group, default=None):
def posix_acl_use_stored_uid_gid(acl):
"""Replace the user/group field with the stored uid/gid
"""
assert isinstance(acl, bytes)
if not isinstance(acl, bytes):
raise TypeError("acl must be of type bytes")
from ..helpers import safe_decode, safe_encode
entries = []
for entry in safe_decode(acl).split('\n'):
Expand Down
Loading