File tree Expand file tree Collapse file tree 2 files changed +24
-2
lines changed
Expand file tree Collapse file tree 2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -18,12 +18,12 @@ cdef croaring.roaring_bitmap_t *deserialize_ptr(bytes buff):
1818 buff_size = len (buff)
1919 ptr = croaring.roaring_bitmap_portable_deserialize_safe(buff, buff_size)
2020 if ptr == NULL :
21- raise ValueError (" Could not deserialize bitmap!! " )
21+ raise ValueError (" Could not deserialize bitmap" )
2222 # Validate the bitmap
2323 if not croaring.roaring_bitmap_internal_validate(ptr, & reason_failure):
2424 # If validation fails, free the bitmap and raise an exception
2525 croaring.roaring_bitmap_free(ptr)
26- raise ValueError (f" Invalid bitmap: {reason_failure.decode('utf-8')}" )
26+ raise ValueError (f" Invalid bitmap after deserialization : {reason_failure.decode('utf-8')}" )
2727 return ptr
2828
2929cdef croaring.roaring64_bitmap_t * deserialize64_ptr(bytes buff):
Original file line number Diff line number Diff line change 1212import operator
1313import unittest
1414import functools
15+ import base64
1516from typing import TYPE_CHECKING
1617from collections .abc import Set , Callable , Iterable , Iterator
1718
@@ -886,6 +887,27 @@ def test_pickle_protocol(
886887 assert old_bm == new_bm
887888 self .assert_is_not (old_bm , new_bm )
888889
890+ @given (bitmap_cls )
891+ def test_impossible_deserialization (
892+ self ,
893+ cls : type [EitherBitMap ],
894+ ) -> None :
895+ wrong_input = base64 .b64decode ('aGVsbG8gd29ybGQ=' )
896+ with pytest .raises (ValueError , match = 'Could not deserialize bitmap' ):
897+ bitmap = cls .deserialize (wrong_input )
898+
899+ @given (bitmap_cls )
900+ def test_invalid_deserialization (
901+ self ,
902+ cls : type [EitherBitMap ],
903+ ) -> None :
904+ wrong_input = base64 .b64decode ('aGVsbG8gd29ybGQ=' )
905+ bm = cls (list (range (0 , 1000000 , 3 )))
906+ bitmap_bytes = bm .serialize ()
907+ bitmap_bytes = bitmap_bytes [:42 ] + wrong_input + bitmap_bytes [42 :]
908+ with pytest .raises (ValueError , match = 'Invalid bitmap after deserialization' ):
909+ bitmap = pyroaring .FrozenBitMap .deserialize (bitmap_bytes )
910+
889911
890912class TestStatistics (Util ):
891913
You can’t perform that action at this time.
0 commit comments