@@ -60,13 +60,11 @@ public static B64Result detect(String str, B64DeobfuscateOptions options) {
6060 }
6161
6262 private static B64Result tryDecode (String str , B64DeobfuscateOptions options ) {
63- B64Result result = attemptDecode (Base64 .getDecoder (), str , options , "" );
64- if (result != null ) {
65- return result ;
66- }
67- result = attemptDecode (Base64 .getUrlDecoder (), str , options , "url" );
68- if (result != null ) {
69- return result ;
63+ for (int i = 0 ; i < STANDARD_AND_URL .length ; i ++) {
64+ B64Result result = attemptDecode (STANDARD_AND_URL [i ], str , options , STANDARD_AND_URL_TAGS [i ]);
65+ if (result != null ) {
66+ return result ;
67+ }
7068 }
7169 // MIME decoder ignores embedded whitespace (PEM line-wrapped Base64)
7270 if (str .indexOf ('\n' ) >= 0 || str .indexOf ('\r' ) >= 0 ) {
@@ -137,13 +135,15 @@ public static B64Result decodeIfValid(String str, int maxCommentLength) {
137135 if (!BASE64_STANDARD .matcher (str ).matches () && !BASE64_URL_SAFE .matcher (str ).matches ()) {
138136 return null ;
139137 }
140- Base64 .Decoder [] decoders = (str .indexOf ('\n' ) >= 0 || str .indexOf ('\r' ) >= 0 )
141- ? ALL_DECODERS : STANDARD_AND_URL ;
142- String [] tags = (str .indexOf ('\n' ) >= 0 || str .indexOf ('\r' ) >= 0 )
143- ? ALL_DECODER_TAGS : STANDARD_AND_URL_TAGS ;
138+ boolean hasLineBreaks = str .indexOf ('\n' ) >= 0 || str .indexOf ('\r' ) >= 0 ;
139+ Base64 .Decoder [] decoders = hasLineBreaks ? ALL_DECODERS : STANDARD_AND_URL ;
140+ String [] tags = hasLineBreaks ? ALL_DECODER_TAGS : STANDARD_AND_URL_TAGS ;
144141 for (int i = 0 ; i < decoders .length ; i ++) {
145142 try {
146143 byte [] bytes = decoders [i ].decode (str );
144+ if (bytes .length == 0 ) {
145+ return null ;
146+ }
147147 CharsetDecoder utf8 = StandardCharsets .UTF_8 .newDecoder ()
148148 .onMalformedInput (CodingErrorAction .REPORT )
149149 .onUnmappableCharacter (CodingErrorAction .REPORT );
0 commit comments