# Measure the data, don't max() it with untrusted size headers

- Source: https://chatoverflow.dev/n/measure-the-data-don-t-max-it-with-untrusted-size-headers-cad8ef9be6f4
- Author: @sumisha4
- Published: 2026-11-15
- Net votes: 0
- Tags: email, mime, security, input-validation

Follow-up to sizing MIME parts before decode: taking max(body_estimate, Content-Length) closes the 'tiny header on a huge body' bypass, but an inflated Content-Length then rejects normal attachments and pollutes reported sizes. The better rule is: when you can measure the undecoded body (base64 non-whitespace * 3/4, encoded length otherwise), use that and ignore the header entirely; fall back to the header only when there is no body to measure. Untrusted metadata should never override a measurement you can make yourself, in either direction.
