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

lws_b64_decode_stateful truncates response #2855

Open
darhaywa opened this issue Mar 23, 2023 · 0 comments
Open

lws_b64_decode_stateful truncates response #2855

darhaywa opened this issue Mar 23, 2023 · 0 comments

Comments

@darhaywa
Copy link
Contributor

Accurately sized output buffers have truncated decodes.

Given the following base64 encoded string of 1708 characters, which decodes to 1279 bytes on https://cryptii.com/pipes/base64-to-binary, when passed through lws_b64_decode_string_len(inputString, 1708, outputBuffer, 1281) only 1278 bytes are returned. This continues until the output buffer size of 1283 is provided.

iVBORw0KGgoAAAANSUhEUgAAADoAAAAdCAYAAAD7En+mAAAAAXNSR0IArs4c6QAAAARzQklUCAgICHwIZIgAAASpSURBVFiF7ZhPSFRdGMZ/XoehIlA0rRFjZCZwoQ4KNgy6UprMlasSRvsjCqIoIUiouBKiTQSiIIgpFFqYGqaiovYHciOD/5UWYpCKTlfFUElR5rT4vrl4m3FGNO3DzwfO4px5z8P7vO9z7zl3/ADB/wDS307gpHAm9LThrwg1Go1YLJYT5xcnOe7duyfm5ubE4uKiePz48Ynxa1JTU3n69CkAHR0dlJSUeK1WW1sbkZGR/Pjxg4SEBK+xGRkZlJWVAVBeXs7bt28xm82cO3cOgOjoaLc9ExMTSJK70ZxOJysrK8zPzzMzM0NfXx+Dg4Nucd74xdTUlJBlWQwODnqtltFoFPPz80KWZSHLssjOzvYa/+rVKyHLsvjy5YuyZjabRX9/v/j8+bOw2WxuexwOh8LvbczOzorCwkK3/fvx+/2bEDdu3GB3d5e0tDSGhoY8dujJkyfk5OQo848fP3L79m2PsQBTU1OEhoby4cMH7ty5s2/cXjgcDiRJ4uvXrwwMDCjrkiQREhKCTqfDZDKh1WrZ2dnhxYsXPl3ogrh7965SqcrKyn079OnTJ1VV93bq9/HgwQMlLicn58DPmKujDQ0N+8akpKSI6elpIcuyWFhYEImJiT55JYCXL1/y/ft3AOLj4z1Ww2Qyce3aNQDevHkDQHBwMLm5uR7jU1NTAVhZWaGurk5Zt1gs2O127HY7eXl5B+iDO3p7e6mqqgJAq9WSkZHhk1956sfGxgAwGAyYzWY38qysLLRaLevr6zx69EgpzM2bNz0mYzKZABgfH1etnz9/Hr1ej16vJygo6FBCAWpqatja2gLgypUrPvkVoV1dXQBoNBpVhVxwiZ+enmZjY0MpjKc3Z3Z2NpcuXQL+qf5xwel0AuDv7+8zVhHa2NiIw+EA3O2bmJiIwWAA4P379wC8e/cOgKCgIPLz81XxKSkpACwvL/P8+fNDifAFm83GhQsXABR3eYPqwHLZzGAwqMTabDY0Gg1ra2s8e/YMgNevX7O4uAiA1WpVkbpsOzExcVgdXhEZGUlxcTEAu7u7tLS0+Nyj2Tvp6urCarWi0WjIzMzEbrcDcP36dQAmJydVm0dHR9HpdCr75ubmEhwcDEBPT8+hxYSHh1NQUKDM/f390el06PV6LBYLFy9exOl00t7efqDHQyW0sbGR0tJSLl++rHTUarWi1+sBVOcaQHt7O7du3SIwMJCHDx9SWVmpdHd5eZn6+vpDC42NjSU2Nnbf37e3t6mtraWiouJAfG53LZd9jUYj8fHxpKenI0kSq6urVFdXq2JbW1tZWFgAIDk5GYCYmBjgz9j258+fytjc3OTbt28MDQ3R3NxMUVHRgUXCbx0F6OzsVNk3Li7Oa+IjIyOEh4cTFRVFQUGB8ko/im1deWRlZR2JYy/cOtrU1KS8fZOSkrh69SoA3d3dHgna2toQQhAQEMD9+/eBo9v2OODxe9R1RoaFheHn54csy/seE52dnczNzQEQEREBuF8S/gvwKNR1eXDBV+LDw8Oq+VFtexzwKLSpqYmlpSVl3tHR4ZWkublZuaXIskxDQ8MfTPHPwI+zvztPF86EnjacCT1t+AUfR6Dl7frSZwAAAABJRU5ErkJggg==

darhaywa added a commit to darhaywa/libwebsockets that referenced this issue Mar 23, 2023
Addresses issue warmcat#2855 by allowing the parsing of the final byte when there are at least 3 bytes remaining in the buffer.

For every 4 bytes of input, a maximum of 3 bytes of output are generated when decoding the base64 string. The buffer space, therefore, only requires an additional 3 bytes of space. The code checks for space in the buffer before adding null termination.
lws-team pushed a commit that referenced this issue Nov 13, 2023
Addresses issue #2855 by allowing the parsing of the final byte when there are at least 3 bytes remaining in the buffer.

For every 4 bytes of input, a maximum of 3 bytes of output are generated when decoding the base64 string. The buffer space, therefore, only requires an additional 3 bytes of space. The code checks for space in the buffer before adding null termination.
lws-team pushed a commit that referenced this issue Nov 13, 2023
Addresses issue #2855 by allowing the parsing of the final byte when there are at least 3 bytes remaining in the buffer.

For every 4 bytes of input, a maximum of 3 bytes of output are generated when decoding the base64 string. The buffer space, therefore, only requires an additional 3 bytes of space. The code checks for space in the buffer before adding null termination.
lws-team pushed a commit that referenced this issue Nov 24, 2023
Addresses issue #2855 by allowing the parsing of the final byte when there are at least 3 bytes remaining in the buffer.

For every 4 bytes of input, a maximum of 3 bytes of output are generated when decoding the base64 string. The buffer space, therefore, only requires an additional 3 bytes of space. The code checks for space in the buffer before adding null termination.
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