Skip to content

Commit 4b8e0a9

Browse files
committed
Fix bounds checking in utf8_validate()
See previous commit for explanation.
1 parent bad0d61 commit 4b8e0a9

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

lib/fizzy/utf8.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ bool utf8_validate(const uint8_t* pos, const uint8_t* end) noexcept
105105
else
106106
return false;
107107

108+
assert(required_bytes > 1);
109+
108110
// At this point need to read at least one more byte
109-
if ((pos + required_bytes - 1) > end)
111+
if ((end - pos) < required_bytes - 1)
110112
return false;
111113

112-
assert(required_bytes > 1);
113114

114115
// Byte2 may have exceptional encodings
115116
const uint8_t byte2 = *pos++;

0 commit comments

Comments
 (0)