File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
msgpack-core/src/main/java/org/msgpack/core Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 2525import java .nio .charset .CharsetDecoder ;
2626import java .nio .charset .CoderResult ;
2727import java .nio .charset .CodingErrorAction ;
28+ import java .nio .charset .MalformedInputException ;
2829
2930import org .msgpack .core .MessagePack .Code ;
3031import org .msgpack .core .buffer .MessageBuffer ;
@@ -968,7 +969,7 @@ public String unpackString() throws IOException {
968969 decodeBuffer .clear ();
969970 StringBuilder sb = new StringBuilder ();
970971 while (cursor < strLen ) {
971- if (! ensureBuffer ( ))
972+ if (! ensure ( strLen ))
972973 throw new EOFException ();
973974
974975 int readLen = Math .min (buffer .size () - position , strLen -cursor );
@@ -987,6 +988,16 @@ public String unpackString() throws IOException {
987988 decoder .reset ();
988989 }
989990
991+ if (cr .isUnderflow () && bb .hasRemaining ()) {
992+ // input buffer doesn't have enough bytes for multi bytes characters
993+ if (config .getActionOnMalFormedInput () == CodingErrorAction .REPORT ) {
994+ throw new MalformedInputException (strLen );
995+ }
996+ // trash truncated bytes
997+ while (bb .hasRemaining ())
998+ bb .get ();
999+ }
1000+
9901001 if (cr .isError ()) {
9911002 if ((cr .isMalformed () && config .getActionOnMalFormedInput () == CodingErrorAction .REPORT ) ||
9921003 (cr .isUnmappable () && config .getActionOnUnmappableCharacter () == CodingErrorAction .REPORT )) {
You can’t perform that action at this time.
0 commit comments