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

Incorrect handling of Base64-encoded values when producing from JSON #227

Open
soundmonster opened this issue Dec 19, 2024 · 0 comments
Open

Comments

@soundmonster
Copy link

Base64-encoded values that start with zeroes result in empty messages when consumed from JSON:

To reproduce:

# create a topic
kafkactl create topic test_base64

# produce a value that starts with zeroes
echo '{"Key": "foo", "Value": "AAAAAAAD"}' | kafkactl produce test_base64 --input-format=json --value-encoding=base64

# produce a value that doesn't start with zeroes, here it's "foo"
echo '{"Key": "bar", "Value": "Zm9v"}' | kafkactl produce test_base64 --input-format=json --value-encoding=base64

# get contents of the topic in JSON format
kafkactl consume test_base64 --value-encoding=base64 --exit --from-beginning --output json

Output:

{
        "Partition": 0,
        "Offset": 0,
        "Value": ""
}
{
        "Partition": 0,
        "Offset": 1,
        "Value": "Zm9v"
}

This seems to be due to the fact that the Base64 decoded byte arrays are assumed to be null-terminated strings and are
truncated at first zero byte, instead of using the decoder return value that signifies the amount of bytes decoded.

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