| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ | |||
| 25 | 25 | import java.nio.charset.CharsetDecoder; | |
| 26 | 26 | import java.nio.charset.CoderResult; | |
| 27 | 27 | import java.nio.charset.CodingErrorAction; | |
| 28 | + import java.nio.charset.MalformedInputException; | ||
| 28 | 29 | ||
| 29 | 30 | import org.msgpack.core.MessagePack.Code; | |
| 30 | 31 | import org.msgpack.core.buffer.MessageBuffer; | |
@@ -968,7 +969,7 @@ public String unpackString() throws IOException { | |||
| 968 | 969 | decodeBuffer.clear(); | |
| 969 | 970 | StringBuilder sb = new StringBuilder(); | |
| 970 | 971 | while(cursor < strLen) { | |
| 971 | - if(!ensureBuffer()) | ||
| 972 | + if (!ensure(strLen)) | ||
| 972 | 973 | throw new EOFException(); | |
| 973 | 974 | ||
| 974 | 975 | int readLen = Math.min(buffer.size() - position, strLen-cursor); | |
@@ -987,6 +988,16 @@ public String unpackString() throws IOException { | |||
| 987 | 988 | decoder.reset(); | |
| 988 | 989 | } | |
| 989 | 990 | ||
| 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 | + | ||
| 990 | 1001 | if(cr.isError()) { | |
| 991 | 1002 | if((cr.isMalformed() && config.getActionOnMalFormedInput() == CodingErrorAction.REPORT) || | |
| 992 | 1003 | (cr.isUnmappable() && config.getActionOnUnmappableCharacter() == CodingErrorAction.REPORT)) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments