@@ -15,6 +15,7 @@ void Utf8DecoderBase::Reset(uint16_t* buffer, size_t buffer_length,
15
15
// Assume everything will fit in the buffer and stream won't be needed.
16
16
last_byte_of_buffer_unused_ = false ;
17
17
unbuffered_start_ = NULL ;
18
+ unbuffered_length_ = 0 ;
18
19
bool writing_to_buffer = true ;
19
20
// Loop until stream is read, writing to buffer as long as buffer has space.
20
21
size_t utf16_length = 0 ;
@@ -41,6 +42,7 @@ void Utf8DecoderBase::Reset(uint16_t* buffer, size_t buffer_length,
41
42
// Just wrote last character of buffer
42
43
writing_to_buffer = false ;
43
44
unbuffered_start_ = stream;
45
+ unbuffered_length_ = stream_length;
44
46
}
45
47
continue ;
46
48
}
@@ -50,19 +52,22 @@ void Utf8DecoderBase::Reset(uint16_t* buffer, size_t buffer_length,
50
52
writing_to_buffer = false ;
51
53
last_byte_of_buffer_unused_ = true ;
52
54
unbuffered_start_ = stream - cursor;
55
+ unbuffered_length_ = stream_length + cursor;
53
56
}
54
57
utf16_length_ = utf16_length;
55
58
}
56
59
57
60
58
- void Utf8DecoderBase::WriteUtf16Slow (const uint8_t * stream, uint16_t * data,
61
+ void Utf8DecoderBase::WriteUtf16Slow (const uint8_t * stream,
62
+ size_t stream_length, uint16_t * data,
59
63
size_t data_length) {
60
64
while (data_length != 0 ) {
61
65
size_t cursor = 0 ;
62
- uint32_t character = Utf8::ValueOf (stream, Utf8:: kMaxEncodedSize , &cursor);
66
+ uint32_t character = Utf8::ValueOf (stream, stream_length , &cursor);
63
67
// There's a total lack of bounds checking for stream
64
68
// as it was already done in Reset.
65
69
stream += cursor;
70
+ stream_length -= cursor;
66
71
if (character > unibrow::Utf16::kMaxNonSurrogateCharCode ) {
67
72
*data++ = Utf16::LeadSurrogate (character);
68
73
*data++ = Utf16::TrailSurrogate (character);
@@ -73,6 +78,7 @@ void Utf8DecoderBase::WriteUtf16Slow(const uint8_t* stream, uint16_t* data,
73
78
data_length -= 1 ;
74
79
}
75
80
}
81
+ DCHECK (stream_length >= 0 );
76
82
}
77
83
78
84
} // namespace unibrow
0 commit comments