@@ -753,16 +753,15 @@ private int decodedOutLength(byte[] src, int sp, int sl) {
753753 * chunks of the src that are of a favorable size for the specific
754754 * processor it's running on.
755755 *
756- * If the intrinsic function does not process all of the bytes in
757- * src, it must process a multiple of four of them, making the
758- * returned destination length a multiple of three.
759- *
760756 * If any illegal base64 bytes are encountered in src by the
761757 * intrinsic, the intrinsic must return the actual number of valid
762758 * data bytes already written to dst. Note that the '=' pad
763759 * character is treated as an illegal Base64 character by
764760 * decodeBlock, so it will not process a block of 4 bytes
765- * containing pad characters.
761+ * containing pad characters. However, MIME decoding ignores
762+ * illegal characters, so any intrinsic overriding decodeBlock
763+ * can choose how to handle illegal characters based on the isMIME
764+ * parameter.
766765 *
767766 * Given the parameters, no length check is possible on dst, so dst
768767 * is assumed to be large enough to store the decoded bytes.
@@ -779,10 +778,12 @@ private int decodedOutLength(byte[] src, int sp, int sl) {
779778 * the offset into dst array to begin writing
780779 * @param isURL
781780 * boolean, when true decode RFC4648 URL-safe base64 characters
781+ * @param isMIME
782+ * boolean, when true decode according to RFC2045 (ignore illegal chars)
782783 * @return the number of destination data bytes produced
783784 */
784785 @ IntrinsicCandidate
785- private int decodeBlock (byte [] src , int sp , int sl , byte [] dst , int dp , boolean isURL ) {
786+ private int decodeBlock (byte [] src , int sp , int sl , byte [] dst , int dp , boolean isURL , boolean isMIME ) {
786787 int [] base64 = isURL ? fromBase64URL : fromBase64 ;
787788 int sl0 = sp + ((sl - sp ) & ~0b11);
788789 int new_dp = dp ;
@@ -810,12 +811,12 @@ private int decode0(byte[] src, int sp, int sl, byte[] dst) {
810811
811812 while (sp < sl ) {
812813 if (shiftto == 18 && sp < sl - 4 ) { // fast path
813- int dl = decodeBlock (src , sp , sl , dst , dp , isURL );
814+ int dl = decodeBlock (src , sp , sl , dst , dp , isURL , isMIME );
814815 /*
815816 * Calculate how many characters were processed by how many
816817 * bytes of data were returned.
817818 */
818- int chars_decoded = (dl / 3 ) * 4 ;
819+ int chars_decoded = (( dl + 2 ) / 3 ) * 4 ;
819820
820821 sp += chars_decoded ;
821822 dp += dl ;
0 commit comments