logoalt Hacker News

userbinator • today at 5:11 AM • 2 replies • view on HN

If you mean ceil(inlen * 4/3) + 1 (even if you use exact arithmetic), then you are passing too small a buffer and you will overflow.

If you let untrusted input reach inlen and overflow that computation, you have already failed:

https://news.ycombinator.com/item?id=50570319


Replies

dns_snek • today at 2:36 PM

inlen isn't an untrusted input and it's not this calculation that's overflowing (integer overflow). It's the buffer that oveflows when you allow the operation to proceed based on faulty validation.

The caller shouldn't be responsible for enforcing preconditions of your function. They should just provide the input buffer, output buffer, their sizes and your implementation should verify whether it's safe to proceed.

amluto • today at 7:08 AM

Are you saying that any code that base64’s a string of attacker-controlled length is a mistake?

➕ show 1 reply