@@ -95,7 +95,8 @@ private static B64Result attemptDecode(Base64.Decoder decoder, String str, B64De
9595 return new B64Result (truncate (decoded , options .getMaxCommentLength ()), tag );
9696 } catch (CharacterCodingException ignored ) {
9797 // decoded bytes are not valid UTF-8
98- } catch (Exception ignored ) {
98+ } catch (IllegalArgumentException ignored ) {
99+ // decoder.decode() rejects malformed Base64
99100 }
100101 return null ;
101102 }
@@ -148,7 +149,8 @@ public static B64Result decodeIfValid(String str, int maxCommentLength) {
148149 .onUnmappableCharacter (CodingErrorAction .REPORT );
149150 String decoded = utf8 .decode (ByteBuffer .wrap (bytes )).toString ();
150151 return new B64Result (truncate (decoded , maxCommentLength ), tags [i ]);
151- } catch (Exception ignored ) {
152+ } catch (IllegalArgumentException | CharacterCodingException ignored ) {
153+ // decoder.decode() rejects malformed Base64; utf8.decode() rejects invalid UTF-8
152154 }
153155 }
154156 return null ;
@@ -169,7 +171,8 @@ public static B64Result decodeForced(String str, int maxCommentLength) {
169171 .onUnmappableCharacter (CodingErrorAction .REPLACE );
170172 String decoded = utf8 .decode (ByteBuffer .wrap (bytes )).toString ();
171173 return new B64Result (truncate (decoded , maxCommentLength ), ALL_DECODER_TAGS [i ]);
172- } catch (Exception ignored ) {
174+ } catch (IllegalArgumentException | CharacterCodingException ignored ) {
175+ // decoder.decode() rejects malformed Base64; utf8.decode() on REPLACE mode won't throw, but guard anyway
173176 }
174177 }
175178 return null ;
0 commit comments