MSVC detected heap corruption from this function when the attachment was 0-bytes in length. Good catch.