Skip to content

Commit eedd518

Browse files
authored
gb18030 decoder: unwind from fourth byte when it's not a digit
Instead of always unwinding if there’s no code point when consuming the fourth byte, only unwind when the fourth byte is not an ASCII digit. This does mean that ASCII digits can be masked, but since ASCII digits are not used as delimiter in any format this is highly unlikely to be used in any attacks (and also matches existing implementations better). Fixes #110.
1 parent 378393f commit eedd518

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

encoding.bs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,25 +1625,24 @@ consumers of content generated with <a>GBK</a>'s <a for=/>encoder</a>.
16251625
<p>If <a>gb18030 third</a> is not 0x00, then:
16261626

16271627
<ol>
1628-
<li><p>Let <var>code point</var> be null.
1628+
<li>
1629+
<p>If <var>byte</var> is not in the range 0x30 to 0x39, inclusive, then:
16291630

1630-
<li><p>If <var>byte</var> is in the range 0x30 to 0x39, inclusive, set
1631-
<var>code point</var> to the
1632-
<a>index gb18030 ranges code point</a> for
1631+
<ol>
1632+
<li><p><a>Prepend</a> <a>gb18030 second</a>, <a>gb18030 third</a>, and <var>byte</var> to
1633+
<var>stream</var>.
1634+
1635+
<li><p>Set <a>gb18030 first</a>, <a>gb18030 second</a>, and <a>gb18030 third</a> to 0x00.
1636+
1637+
<li><p>Return <a>error</a>.
1638+
</ol>
1639+
1640+
<li><p>Let <var>code point</var> be the <a>index gb18030 ranges code point</a> for
16331641
((<a>gb18030 first</a> &minus; 0x81) × (10 × 126 × 10)) +
16341642
((<a>gb18030 second</a> &minus; 0x30) × (10 × 126)) +
16351643
((<a>gb18030 third</a> &minus; 0x81) × 10) + <var>byte</var> &minus; 0x30.
16361644

1637-
<li><p>Let <var>buffer</var> be a byte sequence consisting of
1638-
<a>gb18030 second</a>, <a>gb18030 third</a>, and <var>byte</var>, in
1639-
order.
1640-
1641-
<li><p>Set <a>gb18030 first</a>, <a>gb18030 second</a>, and
1642-
<a>gb18030 third</a> to 0x00.
1643-
1644-
<li><p>If <var>code point</var> is null,
1645-
<a>prepend</a> <var>buffer</var> to
1646-
<var>stream</var> and return <a>error</a>.
1645+
<li><p>If <var>code point</var> is null, return <a>error</a>.
16471646

16481647
<li><p>Return a code point whose value is <var>code point</var>.
16491648
</ol>

0 commit comments

Comments
 (0)