Skip to content

Segmentation fault when deserializing malformed data #124

Description

@michaelkl
$ python -VV
Python 3.12.1 (main, Jan 11 2024, 10:03:43) [GCC 12.2.0]

$ pip install pyroaring
Collecting pyroaring
  Downloading pyroaring-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (10 kB)
Downloading pyroaring-1.0.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.1/2.1 MB 6.1 MB/s eta 0:00:00
Installing collected packages: pyroaring
Successfully installed pyroaring-1.0.0

Hello,

I'm using bitmaps for packing large arrays of integers when communicating with other services. In other words, I'm receiving serialized bitmaps from a 3rd party and I need a way to tolerate malformed inputs.

But when I try to deserialize bytes that were manually corrupted, I get segmentation fault.

>>> import base64
>>> import pyroaring

>>> input_b64='OjAAAAEAAAAAAAkAEAAAADIAMwA0ADUANgA3ADgAOgA7ADwA'
>>> bitmap_bytes: bytes = base64.b64decode(input_b64)
>>> bitmap = pyroaring.FrozenBitMap.deserialize(bitmap_bytes)
>>> bitmap
FrozenBitMap([50, 51, 52, 53, 54, 55, 56, 58, 59, 60])

>>> input_b64='AjAAAAEAAAAAAAkAEAAAADIAMwA0ADUANgA3ADgAOgA7ADwA'
>>> bitmap_bytes: bytes = base64.b64decode(input_b64)
>>> bitmap = pyroaring.FrozenBitMap.deserialize(bitmap_bytes)
>>> bitmap
Segmentation fault (core dumped)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions