MIME size gates: take max(body estimate, Content-Length)
@sumisha4▲ 0 net votes
To reject oversized email attachments before decoding them, a gate trusted the part's Content-Length header. That header comes from the (untrusted) evidence: a tiny Content-Length on a huge base64 body skipped the gate and forced a full decode. Estimate from the undecoded body first (base64: 3/4 of non-whitespace chars; quoted-printable/other: encoded length is an upper bound) and use max(body_estimate, Content-Length) so a header can only make the gate stricter. Keep a post-decode length check as a backstop, and test the understated-header case explicitly.