Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing certain images fails. #155

Open
henrythemouse opened this issue Jun 24, 2020 · 0 comments
Open

Parsing certain images fails. #155

henrythemouse opened this issue Jun 24, 2020 · 0 comments

Comments

@henrythemouse
Copy link

I'm getting parsing errors that seemed to be linked to the syntax of the images in the vcard. Out of 6 images that I've checked (from vcards that were retrieved from a davical server using vdirsyncer) four failed to parse and two parsed without any issue. I discovered this when using khard to search the vcf files. I originally reported this to the khard developer on his github page. He reviewed the issue and suggested that I report it here as he suspects it's an issue with vobject. The two syntaxs are as follows:

FAILS: PHOTO;ENCODING=b;TYPE=png:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA

SUCCESSFUL: PHOTO;ENCODING=B;VALUE=BINARY:/9j/4AAQSkZJRgABAQECWAJYAAD/2wBDAAgGBgcGBQ

I'm using this script to do the test:

import vobject
file = "./whatever.vcf"
with open(file) as f:
    vcard = vobject.readOne(f)
with open(file) as f:
    raw = f.read()
print(vcard.serialize())
print(raw)

In the cases where the parsing fails this is the output:

Traceback (most recent call last):
  File "/usr/lib/python3.8/encodings/base64_codec.py", line 19, in base64_decode
    return (base64.decodebytes(input), len(input))
  File "/usr/lib/python3.8/base64.py", line 546, in decodebytes
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "./vcardtest.py", line 6, in <module>
    vcard = vobject.readOne(f)
  File "/usr/lib/python3/dist-packages/vobject/base.py", line 1155, in readOne
    return next(readComponents(stream, validate, transform, ignoreUnreadable,
  File "/usr/lib/python3/dist-packages/vobject/base.py", line 1120, in readComponents
    component.setBehaviorFromVersionLine(versionLine)
  File "/usr/lib/python3/dist-packages/vobject/base.py", line 663, in setBehaviorFromVersionLine
    self.setBehavior(v)
  File "/usr/lib/python3/dist-packages/vobject/base.py", line 170, in setBehavior
    obj.autoBehavior(True)
  File "/usr/lib/python3/dist-packages/vobject/base.py", line 156, in autoBehavior
    self.behavior.decode(self)
  File "/usr/lib/python3/dist-packages/vobject/vcard.py", line 143, in decode
    line.value = codecs.decode(line.value.encode("utf-8"), "base64")
binascii.Error: decoding with 'base64' codec failed (Error: Incorrect padding)

If this is a vobject issue, Is there any way to work around it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant