@@ -78,7 +78,8 @@ class ChunkIndex(HTProxyMixin, MutableMapping):
7878 flags = self .F_USED
7979 else :
8080 flags = v.flags | self .F_USED
81- assert v.size == 0 or v.size == size
81+ if v.size != 0 and v.size != size:
82+ raise ValueError (f" Invalid size: expected 0 or {size}, got {v.size}" )
8283 self [key] = ChunkIndexEntry(flags = flags, size = size)
8384
8485 def __getitem__ (self , key ):
@@ -217,8 +218,10 @@ class NSIndex1(HTProxyMixin, MutableMapping):
217218 magic, entries, buckets, ksize, vsize = struct .unpack(self .HEADER_FMT, header_bytes)
218219 if magic != self .MAGIC:
219220 raise ValueError (f" Invalid file, magic {self.MAGIC.decode()} not found." )
220- assert ksize == self .KEY_SIZE, " invalid key size"
221- assert vsize == self .VALUE_SIZE, " invalid value size"
221+ if ksize != self .KEY_SIZE:
222+ raise ValueError (" Invalid key size" )
223+ if vsize != self .VALUE_SIZE:
224+ raise ValueError (" Invalid value size" )
222225 buckets_size = buckets * (ksize + vsize)
223226 current_pos = fd.tell()
224227 end_of_file = fd.seek(0 , os.SEEK_END)
@@ -230,4 +233,5 @@ class NSIndex1(HTProxyMixin, MutableMapping):
230233 value = fd.read(vsize)
231234 self .ht._set_raw(key, value)
232235 pos = fd.tell()
233- assert pos == end_of_file
236+ if pos != end_of_file:
237+ raise ValueError (f" Expected pos ({pos}) to be at end_of_file ({end_of_file})" )
0 commit comments