Skip to content

[Bug] vBinary class causes image bytes to become corrupt #1289

@FilipAtanasovski-dev

Description

@FilipAtanasovski-dev

Describe the bug

The vBinary class corrupts image files if loaded in.

To reproduce

from icalendar import vBinary
import base64

# 1. Create a small "image" payload (pretend PNG header + fake data)
original_bytes = (
    b"\x89PNG\r\n\x1a\n"  # PNG signature
    b"\x00\x00\x00\rIHDR"  # fake chunk
    b"\x00\x00\x00\x01\x00\x00\x00\x01"
)

# 2. Wrap it into vBinary
vb = vBinary(original_bytes)

# 3. Serialize to iCal base64 form
ical_encoded = vb.to_ical()

# 4. Decode back using the library method
decoded_bytes = vBinary.from_ical(ical_encoded)

# 5. Save both to files for comparison
print("Original bytes:", original_bytes)
print("Decoded bytes:", decoded_bytes)

print("Match:", original_bytes == decoded_bytes)
### ...

Output:

Original bytes: b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01'
Decoded bytes: b'\xef\xbf\xbdPNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01'
Match: False

Expected behavior

Original bytes: b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01'
Decoded bytes: b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01'
Match: True

Environment

  • Operating system: Windows 11
  • Python version: 3.13.1
  • icalendar version: 7.0.4.dev127

Additional context

  • I tested it with the latest version. For example, I used the command pip3 install --upgrade https://github.com/collective/icalendar.git.
  • I attached the .ics sample file, or there is no .ics sample file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions