agronholm / cbor2

Python CBOR (de)serializer with extensive tag support
MIT License
226 stars 59 forks source link

SystemError raised for invalid function signature in object_hook callback. #205

Closed kohlerjl closed 10 months ago

kohlerjl commented 10 months ago

Things to check first

cbor2 version

5.5.1

Python version

3.8

What happened?

If the function signature of the object_hook callback is incorrect, loads raises "SystemError: returned a result with an error set".

I would expect the original TypeError to be propagated up. This issue does not seem to affect the default callback in dumps

How can we reproduce the bug?

import cbor2
import pytest

def test_invalid_object_hook():
    def invalid_object_hook(obj):
        return obj

    obj = {
        'a': 1,
        'hello': 'world',
        'obj': {
            'foo': 'bar'
        },
    }
    data = cbor2.dumps(obj)
    with pytest.raises(TypeError):
        cbor2.loads(data, object_hook=invalid_object_hook)
agronholm commented 10 months ago

I can't reproduce this on master, so I'm closing this. Let me know if this was in error.

kohlerjl commented 10 months ago

You're right, I just tested on master and confirmed it works. Must have already been fixed by other changes since the last release. Thanks for taking a look.