Skip to content

Conversation

@bagder
Copy link
Member

@bagder bagder commented Sep 19, 2025

We used to treat 0 as "call strlen() to get the length" for curlx_base64_encode, but it turns out this is rather fragile as we easily do the mistake of passing in zero when the data is actually not there and then calling strlen() is wrong.

Force the caller to pass in the correct size. Encoding a zero length string now returns a zero length output and a NULL pointer.

@bagder bagder changed the title base64: forbid zero length argument to base64_encode base64: allow zero length argument to base64_encode Sep 19, 2025
bagder added a commit that referenced this pull request Sep 19, 2025
We used to treat 0 as "call strlen() to get the length" for
curlx_base64_encode, but it turns out this is rather fragile as we
easily do the mistake of passing in zero when the data is actually not
there and then calling strlen() is wrong.

Force the caller to pass in the correct size. A zero length input string
now returns a zero length output and a NULL pointer.

Closes #18617
@bagder bagder force-pushed the bagder/base64-zero-length branch from cfc7f62 to 680fecd Compare September 19, 2025 12:07
@github-actions github-actions bot added the tests label Sep 19, 2025
We used to treat 0 as "call strlen() to get the length" for
curlx_base64_encode, but it turns out this is rather fragile as we
easily do the mistake of passing in zero when the data is actually not
there and then calling strlen() is wrong.

Force the caller to pass in the correct size. A zero length input string
now returns a zero length output and a NULL pointer.

Closes #18617
@bagder bagder force-pushed the bagder/base64-zero-length branch from 26cc180 to e5e65ab Compare September 19, 2025 12:32
@bagder bagder marked this pull request as ready for review September 19, 2025 12:34
@bagder bagder closed this in 5e2d4d7 Sep 19, 2025
@bagder bagder deleted the bagder/base64-zero-length branch September 19, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

1 participant