Merge pull request #136 from keywan-ghadami/fix-linestream-buffer-overflow

fix bufferoverflow
This commit is contained in:
Vadim Lopatin 2015-12-29 11:32:00 +03:00
commit 483780ac96
1 changed files with 9 additions and 1 deletions

View File

@ -577,7 +577,8 @@ private class Utf8LineStream : LineStream {
uint len = bytesAvailable; uint len = bytesAvailable;
uint chars = 0; uint chars = 0;
ubyte* b = bytes; ubyte* b = bytes;
dchar* text = reserveTextBuf(len); uint maxResultingBytes = len*2; //len*2 because worst case is if all input chars are singelbyte and resulting in two bytes
dchar* text = reserveTextBuf(maxResultingBytes);
uint i = 0; uint i = 0;
for (; i < len; i++) { for (; i < len; i++) {
uint ch = 0; uint ch = 0;
@ -658,6 +659,13 @@ private class Utf8LineStream : LineStream {
invalidCharFlag = true; invalidCharFlag = true;
break; break;
} }
//if the code above could not read any charater stop procesing
if (bread == 0) {
invalidCharFlag = true;
break;
}
if (ch < 0x10000) { if (ch < 0x10000) {
text[chars++] = ch; text[chars++] = ch;
} else { } else {