Skip to content

Conversation

@zhangjy1014
Copy link

The htp_base64_decode function previously performed a write to the output buffer (*plainchar) to store the partial result of the next byte before verifying if the output buffer had sufficient space. This resulted in a heap-buffer-overflow when the provided output buffer was undersized or exactly full.

This patch fixes the issue by:

  1. Moving the partial byte assignment after the buffer length check.
  2. Correctly updating the decoder state (decoder->step and decoder->plainchar) when the buffer limit is reached, ensuring the state is preserved without writing out-of-bounds.

Fixes #458

This patch is generated by ASKRepair, an agentic automated vulnerability repair framework

The htp_base64_decode function previously performed a write to the
output buffer (*plainchar) to store the partial result of the next
byte before verifying if the output buffer had sufficient space.
This resulted in a heap-buffer-overflow when the provided output
buffer was undersized or exactly full.

This patch fixes the issue by:
1. Moving the partial byte assignment after the buffer length check.
2. Correctly updating the decoder state (decoder->step and
   decoder->plainchar) when the buffer limit is reached, ensuring
   the state is preserved without writing out-of-bounds.

Fixes OISF#458
@zhangjy1014
Copy link
Author

Hi @catenacyber, please take a look

@catenacyber
Copy link
Contributor

Thanks for the work.
Could we have some tests for the different cases ?

@zhangjy1014
Copy link
Author

Hi @catenacyber, thanks for your review, I've added several tests. The patched version passes all of them, while the unpatched version triggers an ASan error on each of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Out-of-bounds write in htp_base64_decode

2 participants