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

Serialization Issue with Pickle Protocol 4 #260

Open
CodeTerminator007 opened this issue Aug 24, 2023 · 0 comments
Open

Serialization Issue with Pickle Protocol 4 #260

CodeTerminator007 opened this issue Aug 24, 2023 · 0 comments

Comments

@CodeTerminator007
Copy link

Description:

Problem:
I've encountered an issue with the Stream-Framework library's ActivitySerializer class when using the Pickle protocol 4. The serialization process seems to fail when the serialized data contains a semicolon character, which leads to unexpected behavior.

Code Sample:

def dumps(self, activity):
    self.check_type(activity)
    activity_time = '%.6f' % datetime_to_epoch(activity.time)
    parts = [activity.actor_id, activity.verb.id,
             activity.object_id, activity.target_id or 0]
    extra_context = activity.extra_context.copy()
    pickle_string = ''
    if extra_context:
        pickle_string = pickle.dumps(activity.extra_context)
        if six.PY3:
            pickle_string = pickle_string.decode('latin1')
    parts += [activity_time, pickle_string]
    serialized_activity = ','.join(map(str, parts))
    return serialized_activity

Issue Details:
In the above code snippet, when using the Pickle protocol 4, if the activity.extra_context contains a semicolon character, the serialization process breaks. This appears to be due to changes in the Pickle module's behavior between protocol versions 3 and 4.

Steps to Reproduce:

if we do this we get semicolon
pickle.dumps({'actor_type': 'brand', 'description': 'Some Description'})
output:  b'\x80\x04\x95;\x00\x00\x00\x00\x00\x00\x00}\x94(\x8c\nactor_type\x94\x8c\x05brand\x94\x8c\x0bdescription\x94\x8c\x10Some Description\x94u.'

But if we do use protocol 3 then no semicolon

pickle.dumps({'actor_type': 'brand', 'description': 'Some Description'}, protocol=3)
output: b'\x80\x03}q\x00(X\n\x00\x00\x00actor_typeq\x01X\x05\x00\x00\x00brandq\x02X\x0b\x00\x00\x00descriptionq\x03X\x10\x00\x00\x00Some Descriptionq\x04u.'

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