<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[209586] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/209586">209586</a></dd>
<dt>Author</dt> <dd>keith_miller@apple.com</dd>
<dt>Date</dt> <dd>2016-12-08 17:34:05 -0800 (Thu, 08 Dec 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add 64-bit signed LEB decode method
https://bugs.webkit.org/show_bug.cgi?id=165630
Reviewed by Ryosuke Niwa.
Source/WTF:
Add int64 LEB decode and fix some 64-bit specific issues
with the decoder. There is also a fix where we would allow
LEBs with canonical length + 1 size that is fixed by this
patch.
* wtf/LEBDecoder.h:
(WTF::LEBDecoder::decodeUInt):
(WTF::LEBDecoder::decodeInt):
(WTF::LEBDecoder::decodeUInt32):
(WTF::LEBDecoder::decodeUInt64):
(WTF::LEBDecoder::decodeInt32):
(WTF::LEBDecoder::decodeInt64):
Tools:
Add tests for LEB int64 and uint64 decode since I guess
I forgot to add tests before.
* TestWebKitAPI/Tests/WTF/LEBDecoder.cpp:
(TestWebKitAPI::testUInt32LEBDecode):
(TestWebKitAPI::TEST):
(TestWebKitAPI::testUInt64LEBDecode):
(TestWebKitAPI::testInt32LEBDecode):
(TestWebKitAPI::testInt64LEBDecode):
(TestWebKitAPI::testUnsignedLEBDecode): Deleted.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfLEBDecoderh">trunk/Source/WTF/wtf/LEBDecoder.h</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestsWTFLEBDecodercpp">trunk/Tools/TestWebKitAPI/Tests/WTF/LEBDecoder.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (209585 => 209586)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-12-09 01:21:15 UTC (rev 209585)
+++ trunk/Source/WTF/ChangeLog        2016-12-09 01:34:05 UTC (rev 209586)
</span><span class="lines">@@ -1,3 +1,23 @@
</span><ins>+2016-12-08 Keith Miller <keith_miller@apple.com>
+
+ Add 64-bit signed LEB decode method
+ https://bugs.webkit.org/show_bug.cgi?id=165630
+
+ Reviewed by Ryosuke Niwa.
+
+ Add int64 LEB decode and fix some 64-bit specific issues
+ with the decoder. There is also a fix where we would allow
+ LEBs with canonical length + 1 size that is fixed by this
+ patch.
+
+ * wtf/LEBDecoder.h:
+ (WTF::LEBDecoder::decodeUInt):
+ (WTF::LEBDecoder::decodeInt):
+ (WTF::LEBDecoder::decodeUInt32):
+ (WTF::LEBDecoder::decodeUInt64):
+ (WTF::LEBDecoder::decodeInt32):
+ (WTF::LEBDecoder::decodeInt64):
+
</ins><span class="cx"> 2016-12-08 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Defer sending Mach messages if the queue is full
</span></span></pre></div>
<a id="trunkSourceWTFwtfLEBDecoderh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/LEBDecoder.h (209585 => 209586)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/LEBDecoder.h        2016-12-09 01:21:15 UTC (rev 209585)
+++ trunk/Source/WTF/wtf/LEBDecoder.h        2016-12-09 01:34:05 UTC (rev 209586)
</span><span class="lines">@@ -34,17 +34,19 @@
</span><span class="cx">
</span><span class="cx"> namespace WTF { namespace LEBDecoder {
</span><span class="cx">
</span><del>-template<size_t maxByteLength, typename T>
</del><ins>+template<typename T>
</ins><span class="cx"> inline bool WARN_UNUSED_RETURN decodeUInt(const uint8_t* bytes, size_t length, size_t& offset, T& result)
</span><span class="cx"> {
</span><ins>+ const size_t numBits = sizeof(T) * CHAR_BIT;
+ const size_t maxByteLength = (numBits - 1) / 7 + 1; // numBits / 7 rounding up.
</ins><span class="cx"> if (length <= offset)
</span><span class="cx"> return false;
</span><span class="cx"> result = 0;
</span><span class="cx"> unsigned shift = 0;
</span><del>- size_t last = std::min(maxByteLength, length - offset - 1);
</del><ins>+ size_t last = std::min(maxByteLength, length - offset) - 1;
</ins><span class="cx"> for (unsigned i = 0; true; ++i) {
</span><span class="cx"> uint8_t byte = bytes[offset++];
</span><del>- result |= (byte & 0x7f) << shift;
</del><ins>+ result |= static_cast<T>(byte & 0x7f) << shift;
</ins><span class="cx"> shift += 7;
</span><span class="cx"> if (!(byte & 0x80))
</span><span class="cx"> return true;
</span><span class="lines">@@ -55,30 +57,20 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-const size_t max32BitLEBByteLength = 5;
-const size_t max64BitLEBByteLength = 10;
-
-inline bool WARN_UNUSED_RETURN decodeUInt32(const uint8_t* bytes, size_t length, size_t& offset, uint32_t& result)
</del><ins>+template<typename T>
+inline bool WARN_UNUSED_RETURN decodeInt(const uint8_t* bytes, size_t length, size_t& offset, T& result)
</ins><span class="cx"> {
</span><del>- return decodeUInt<max32BitLEBByteLength, uint32_t>(bytes, length, offset, result);
-}
-
-inline bool WARN_UNUSED_RETURN decodeUInt64(const uint8_t* bytes, size_t length, size_t& offset, uint64_t& result)
-{
- return decodeUInt<max64BitLEBByteLength, uint64_t>(bytes, length, offset, result);
-}
-
-inline bool WARN_UNUSED_RETURN decodeInt32(const uint8_t* bytes, size_t length, size_t& offset, int32_t& result)
-{
</del><ins>+ const size_t numBits = sizeof(T) * CHAR_BIT;
+ const size_t maxByteLength = (numBits - 1) / 7 + 1; // numBits / 7 rounding up.
</ins><span class="cx"> if (length <= offset)
</span><span class="cx"> return false;
</span><span class="cx"> result = 0;
</span><span class="cx"> unsigned shift = 0;
</span><del>- size_t last = std::min(max32BitLEBByteLength, length - offset - 1);
</del><ins>+ size_t last = std::min(maxByteLength, length - offset) - 1;
</ins><span class="cx"> uint8_t byte;
</span><span class="cx"> for (unsigned i = 0; true; ++i) {
</span><span class="cx"> byte = bytes[offset++];
</span><del>- result |= (byte & 0x7f) << shift;
</del><ins>+ result |= static_cast<T>(byte & 0x7f) << shift;
</ins><span class="cx"> shift += 7;
</span><span class="cx"> if (!(byte & 0x80))
</span><span class="cx"> break;
</span><span class="lines">@@ -86,9 +78,29 @@
</span><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if (shift < 32 && (byte & 0x40))
- result |= ((-1u) << shift);
</del><ins>+ if (shift < numBits && (byte & 0x40))
+ result |= static_cast<T>(-1) << shift;
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+inline bool WARN_UNUSED_RETURN decodeUInt32(const uint8_t* bytes, size_t length, size_t& offset, uint32_t& result)
+{
+ return decodeUInt<uint32_t>(bytes, length, offset, result);
+}
+
+inline bool WARN_UNUSED_RETURN decodeUInt64(const uint8_t* bytes, size_t length, size_t& offset, uint64_t& result)
+{
+ return decodeUInt<uint64_t>(bytes, length, offset, result);
+}
+
+inline bool WARN_UNUSED_RETURN decodeInt32(const uint8_t* bytes, size_t length, size_t& offset, int32_t& result)
+{
+ return decodeInt<int32_t>(bytes, length, offset, result);
+}
+
+inline bool WARN_UNUSED_RETURN decodeInt64(const uint8_t* bytes, size_t length, size_t& offset, int64_t& result)
+{
+ return decodeInt<int64_t>(bytes, length, offset, result);
+}
+
</ins><span class="cx"> } } // WTF::LEBDecoder
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (209585 => 209586)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2016-12-09 01:21:15 UTC (rev 209585)
+++ trunk/Tools/ChangeLog        2016-12-09 01:34:05 UTC (rev 209586)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-12-08 Keith Miller <keith_miller@apple.com>
+
+ Add 64-bit signed LEB decode method
+ https://bugs.webkit.org/show_bug.cgi?id=165630
+
+ Reviewed by Ryosuke Niwa.
+
+ Add tests for LEB int64 and uint64 decode since I guess
+ I forgot to add tests before.
+
+ * TestWebKitAPI/Tests/WTF/LEBDecoder.cpp:
+ (TestWebKitAPI::testUInt32LEBDecode):
+ (TestWebKitAPI::TEST):
+ (TestWebKitAPI::testUInt64LEBDecode):
+ (TestWebKitAPI::testInt32LEBDecode):
+ (TestWebKitAPI::testInt64LEBDecode):
+ (TestWebKitAPI::testUnsignedLEBDecode): Deleted.
+
</ins><span class="cx"> 2016-12-08 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> Make it easy to enable --force-collectContinuously
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWTFLEBDecodercpp"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/LEBDecoder.cpp (209585 => 209586)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WTF/LEBDecoder.cpp        2016-12-09 01:21:15 UTC (rev 209585)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/LEBDecoder.cpp        2016-12-09 01:34:05 UTC (rev 209586)
</span><span class="lines">@@ -30,15 +30,15 @@
</span><span class="cx">
</span><span class="cx"> namespace TestWebKitAPI {
</span><span class="cx">
</span><del>-static void testUnsignedLEBDecode(std::initializer_list<uint8_t> data, size_t startOffset, bool expectedStatus, uint32_t expectedResult, size_t expectedOffset)
</del><ins>+static void testUInt32LEBDecode(std::initializer_list<uint8_t> data, size_t startOffset, bool expectedStatus, uint32_t expectedResult, size_t expectedOffset)
</ins><span class="cx"> {
</span><span class="cx"> Vector<uint8_t> vector(data);
</span><span class="cx"> uint32_t result;
</span><span class="cx"> bool status = WTF::LEBDecoder::decodeUInt32(vector.data(), vector.size(), startOffset, result);
</span><del>- EXPECT_EQ(status, expectedStatus);
</del><ins>+ EXPECT_EQ(expectedStatus, status);
</ins><span class="cx"> if (expectedStatus) {
</span><del>- EXPECT_EQ(result, expectedResult);
- EXPECT_EQ(startOffset, expectedOffset);
</del><ins>+ EXPECT_EQ(expectedResult, result);
+ EXPECT_EQ(expectedOffset, startOffset);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -45,47 +45,107 @@
</span><span class="cx"> TEST(WTF, LEBDecoderUInt32)
</span><span class="cx"> {
</span><span class="cx"> // Simple tests that use all the bits in the array
</span><del>- testUnsignedLEBDecode({ 0x07 }, 0, true, 0x7lu, 1lu);
- testUnsignedLEBDecode({ 0x77 }, 0, true, 0x77lu, 1lu);
- testUnsignedLEBDecode({ 0x80, 0x07 }, 0, true, 0x380lu, 2lu);
- testUnsignedLEBDecode({ 0x89, 0x12 }, 0, true, 0x909lu, 2lu);
- testUnsignedLEBDecode({ 0xf3, 0x85, 0x02 }, 0, true, 0x82f3lu, 3lu);
- testUnsignedLEBDecode({ 0xf3, 0x85, 0xff, 0x74 }, 0, true, 0xe9fc2f3lu, 4lu);
- testUnsignedLEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x7f }, 0, true, 0xfe9fc2f3lu, 5lu);
</del><ins>+ testUInt32LEBDecode({ 0x07 }, 0, true, 0x7lu, 1lu);
+ testUInt32LEBDecode({ 0x77 }, 0, true, 0x77lu, 1lu);
+ testUInt32LEBDecode({ 0x80, 0x07 }, 0, true, 0x380lu, 2lu);
+ testUInt32LEBDecode({ 0x89, 0x12 }, 0, true, 0x909lu, 2lu);
+ testUInt32LEBDecode({ 0xf3, 0x85, 0x02 }, 0, true, 0x82f3lu, 3lu);
+ testUInt32LEBDecode({ 0xf3, 0x85, 0xff, 0x74 }, 0, true, 0xe9fc2f3lu, 4lu);
+ testUInt32LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x7f }, 0, true, 0xfe9fc2f3lu, 5lu);
</ins><span class="cx"> // Test with extra trailing numbers
</span><del>- testUnsignedLEBDecode({ 0x07, 0x80 }, 0, true, 0x7lu, 1lu);
- testUnsignedLEBDecode({ 0x07, 0x75 }, 0, true, 0x7lu, 1lu);
- testUnsignedLEBDecode({ 0xf3, 0x85, 0xff, 0x74, 0x43 }, 0, true, 0xe9fc2f3lu, 4lu);
- testUnsignedLEBDecode({ 0xf3, 0x85, 0xff, 0x74, 0x80 }, 0, true, 0xe9fc2f3lu, 4lu);
</del><ins>+ testUInt32LEBDecode({ 0x07, 0x80 }, 0, true, 0x7lu, 1lu);
+ testUInt32LEBDecode({ 0x07, 0x75 }, 0, true, 0x7lu, 1lu);
+ testUInt32LEBDecode({ 0xf3, 0x85, 0xff, 0x74, 0x43 }, 0, true, 0xe9fc2f3lu, 4lu);
+ testUInt32LEBDecode({ 0xf3, 0x85, 0xff, 0x74, 0x80 }, 0, true, 0xe9fc2f3lu, 4lu);
</ins><span class="cx"> // Test with preceeding numbers
</span><del>- testUnsignedLEBDecode({ 0xf3, 0x07 }, 1, true, 0x7lu, 2lu);
- testUnsignedLEBDecode({ 0x03, 0x07 }, 1, true, 0x7lu, 2lu);
- testUnsignedLEBDecode({ 0xf2, 0x53, 0x43, 0x67, 0x79, 0x77 }, 5, true, 0x77lu, 6lu);
- testUnsignedLEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77 }, 5, true, 0x77lu, 6ul);
- testUnsignedLEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02 }, 3, true, 0x82f3lu, 6lu);
</del><ins>+ testUInt32LEBDecode({ 0xf3, 0x07 }, 1, true, 0x7lu, 2lu);
+ testUInt32LEBDecode({ 0x03, 0x07 }, 1, true, 0x7lu, 2lu);
+ testUInt32LEBDecode({ 0xf2, 0x53, 0x43, 0x67, 0x79, 0x77 }, 5, true, 0x77lu, 6lu);
+ testUInt32LEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77 }, 5, true, 0x77lu, 6ul);
+ testUInt32LEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02 }, 3, true, 0x82f3lu, 6lu);
</ins><span class="cx"> // Test in the middle
</span><del>- testUnsignedLEBDecode({ 0xf3, 0x07, 0x89 }, 1, true, 0x7lu, 2lu);
- testUnsignedLEBDecode({ 0x03, 0x07, 0x23 }, 1, true, 0x7lu, 2lu);
- testUnsignedLEBDecode({ 0xf2, 0x53, 0x43, 0x67, 0x79, 0x77, 0x43 }, 5, true, 0x77lu, 6lu);
- testUnsignedLEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77, 0xf9 }, 5, true, 0x77lu, 6lu);
- testUnsignedLEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02, 0xa4 }, 3, true, 0x82f3lu, 6lu);
</del><ins>+ testUInt32LEBDecode({ 0xf3, 0x07, 0x89 }, 1, true, 0x7lu, 2lu);
+ testUInt32LEBDecode({ 0x03, 0x07, 0x23 }, 1, true, 0x7lu, 2lu);
+ testUInt32LEBDecode({ 0xf2, 0x53, 0x43, 0x67, 0x79, 0x77, 0x43 }, 5, true, 0x77lu, 6lu);
+ testUInt32LEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77, 0xf9 }, 5, true, 0x77lu, 6lu);
+ testUInt32LEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02, 0xa4 }, 3, true, 0x82f3lu, 6lu);
</ins><span class="cx"> // Test decode too long
</span><del>- testUnsignedLEBDecode({ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}, 0, false, 0x0lu, 0lu);
- testUnsignedLEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff}, 1, false, 0x0lu, 0lu);
- testUnsignedLEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff}, 0, false, 0x0lu, 0lu);
</del><ins>+ testUInt32LEBDecode({ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }, 0, false, 0x0lu, 0lu);
+ testUInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 1, false, 0x0lu, 0lu);
+ testUInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 0, false, 0x0lu, 0lu);
</ins><span class="cx"> // Test decode off end of array
</span><del>- testUnsignedLEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff}, 2, false, 0x0lu, 0lu);
</del><ins>+ testUInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 2, false, 0x0lu, 0lu);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+static void testUInt64LEBDecode(std::initializer_list<uint8_t> data, size_t startOffset, bool expectedStatus, uint64_t expectedResult, size_t expectedOffset)
+{
+ Vector<uint8_t> vector(data);
+ uint64_t result;
+ bool status = WTF::LEBDecoder::decodeUInt64(vector.data(), vector.size(), startOffset, result);
+ EXPECT_EQ(expectedStatus, status);
+ if (expectedStatus) {
+ EXPECT_EQ(expectedResult, result);
+ EXPECT_EQ(expectedOffset, startOffset);
+ }
+}
+
+TEST(WTF, LEBDecoderUInt64)
+{
+ // Simple tests that use all the bits in the array
+ testUInt64LEBDecode({ 0x07 }, 0, true, 0x7lu, 1lu);
+ testUInt64LEBDecode({ 0x77 }, 0, true, 0x77lu, 1lu);
+ testUInt64LEBDecode({ 0x80, 0x07 }, 0, true, 0x380lu, 2lu);
+ testUInt64LEBDecode({ 0x89, 0x12 }, 0, true, 0x909lu, 2lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0x02 }, 0, true, 0x82f3lu, 3lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0x74 }, 0, true, 0xe9fc2f3lu, 4lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x7f }, 0, true, 0x7fe9fc2f3lu, 5lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0xff, 0x4b }, 0, true, 0x25ffe9fc2f3lu, 6lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0x3a }, 0, true, 0xea5ffe9fc2f3lu, 7lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x0f }, 0, true, 0x1eea5ffe9fc2f3lu, 8lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f, 0x69 }, 0, true, 0x691eea5ffe9fc2f3lu, 9lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f, 0xe9, 0x01 }, 0, true, 0xe91eea5ffe9fc2f3lu, 10lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f, 0xe9, 0x70 }, 0, true, 0x691eea5ffe9fc2f3lu, 10lu);
+ // Test with extra trailing numbers
+ testUInt64LEBDecode({ 0x07, 0x80 }, 0, true, 0x7lu, 1lu);
+ testUInt64LEBDecode({ 0x07, 0x75 }, 0, true, 0x7lu, 1lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0x74, 0x43 }, 0, true, 0xe9fc2f3lu, 4lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0x74, 0x80 }, 0, true, 0xe9fc2f3lu, 4lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f, 0x69, 0x45 }, 0, true, 0x691eea5ffe9fc2f3lu, 9lu);
+ // Test with preceeding numbers
+ testUInt64LEBDecode({ 0xf3, 0x07 }, 1, true, 0x7lu, 2lu);
+ testUInt64LEBDecode({ 0x03, 0x07 }, 1, true, 0x7lu, 2lu);
+ testUInt64LEBDecode({ 0xf2, 0x53, 0x43, 0x67, 0x79, 0x77 }, 5, true, 0x77lu, 6lu);
+ testUInt64LEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77 }, 5, true, 0x77lu, 6ul);
+ testUInt64LEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02 }, 3, true, 0x82f3lu, 6lu);
+ testUInt64LEBDecode({ 0x92, 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f, 0x69 }, 1, true, 0x691eea5ffe9fc2f3lu, 10lu);
+ // Test in the middle
+ testUInt64LEBDecode({ 0xf3, 0x07, 0x89 }, 1, true, 0x7lu, 2lu);
+ testUInt64LEBDecode({ 0x03, 0x07, 0x23 }, 1, true, 0x7lu, 2lu);
+ testUInt64LEBDecode({ 0xf2, 0x53, 0x43, 0x67, 0x79, 0x77, 0x43 }, 5, true, 0x77lu, 6lu);
+ testUInt64LEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77, 0xf9 }, 5, true, 0x77lu, 6lu);
+ testUInt64LEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02, 0xa4 }, 3, true, 0x82f3lu, 6lu);
+ testUInt64LEBDecode({ 0x92, 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f, 0x69, 0x85, 0x75 }, 1, true, 0x691eea5ffe9fc2f3lu, 10lu);
+ testUInt64LEBDecode({ 0x92, 0x65, 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f, 0x69, 0x85, 0x75 }, 2, true, 0x691eea5ffe9fc2f3lu, 11lu);
+ // Test decode too long
+ testUInt64LEBDecode({ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }, 0, false, 0x0lu, 0lu);
+ testUInt64LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xa3, 0x9f, 0xd2, 0xef, 0x8a, 0x4e }, 1, false, 0x0lu, 0lu);
+ testUInt64LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff, 0xef, 0xd8, 0xee, 0xaa, 0xbb }, 0, false, 0x0lu, 0lu);
+ testUInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f, 0xa9, 0xa8, 0x05 }, 0, false, 0x0lu, 0lu);
+ // Test decode off end of array
+ testUInt64LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 2, false, 0x0lu, 0lu);
+ testUInt64LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 2, false, 0x0lu, 0lu);
+ testUInt64LEBDecode({ 0x92, 0xf3, 0x85, 0xff, 0xf4, 0xff, 0xcb, 0xba, 0x8f }, 1, false, 0x0lu, 0lu);
+}
+
</ins><span class="cx"> static void testInt32LEBDecode(std::initializer_list<uint8_t> data, size_t startOffset, bool expectedStatus, int32_t expectedResult, size_t expectedOffset)
</span><span class="cx"> {
</span><span class="cx"> Vector<uint8_t> vector(data);
</span><span class="cx"> int32_t result;
</span><span class="cx"> bool status = WTF::LEBDecoder::decodeInt32(vector.data(), vector.size(), startOffset, result);
</span><del>- EXPECT_EQ(status, expectedStatus);
</del><ins>+ EXPECT_EQ(expectedStatus, status);
</ins><span class="cx"> if (expectedStatus) {
</span><del>- EXPECT_EQ(result, expectedResult);
- EXPECT_EQ(startOffset, expectedOffset);
</del><ins>+ EXPECT_EQ(expectedResult, result);
+ EXPECT_EQ(expectedOffset, startOffset);
</ins><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -117,11 +177,65 @@
</span><span class="cx"> testInt32LEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77, 0xf9 }, 5, true, -0x9, 6lu);
</span><span class="cx"> testInt32LEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02, 0xa4 }, 3, true, 0x82f3, 6lu);
</span><span class="cx"> // Test decode too long
</span><del>- testInt32LEBDecode({ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80}, 0, false, 0x0, 0lu);
- testInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff}, 1, false, 0x0, 0lu);
- testInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff}, 0, false, 0x0, 0lu);
</del><ins>+ testInt32LEBDecode({ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }, 0, false, 0x0, 0lu);
+ testInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 1, false, 0x0, 0lu);
+ testInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 0, false, 0x0, 0lu);
</ins><span class="cx"> // Test decode off end of array
</span><del>- testInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff}, 2, false, 0x0, 0lu);
</del><ins>+ testInt32LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 2, false, 0x0, 0lu);
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+static void testInt64LEBDecode(std::initializer_list<uint8_t> data, size_t startOffset, bool expectedStatus, int64_t expectedResult, size_t expectedOffset)
+{
+ Vector<uint8_t> vector(data);
+ int64_t result;
+ bool status = WTF::LEBDecoder::decodeInt64(vector.data(), vector.size(), startOffset, result);
+ EXPECT_EQ(expectedStatus, status);
+ if (expectedStatus) {
+ EXPECT_EQ(expectedResult, result);
+ EXPECT_EQ(expectedOffset, startOffset);
+ }
+}
+
+TEST(WTF, LEBDecoderInt64)
+{
+ // Simple tests that use all the bits in the array
+ testInt64LEBDecode({ 0x07 }, 0, true, 0x7, 1lu);
+ testInt64LEBDecode({ 0x77 }, 0, true, -0x9, 1lu);
+ testInt64LEBDecode({ 0x80, 0x07 }, 0, true, 0x380, 2lu);
+ testInt64LEBDecode({ 0x89, 0x12 }, 0, true, 0x909, 2lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0x02 }, 0, true, 0x82f3, 3lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0x74 }, 0, true, 0xfffffffffe9fc2f3, 4lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x7f }, 0, true, 0xfffffffffe9fc2f3, 5lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x3f }, 0, true, 0x3fe9fc2f3, 5lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x8f, 0x1a }, 0, true, 0xd0fe9fc2f3, 6lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x8f, 0x9a, 0x80, 0x2a }, 0, true, 0x5400d0fe9fc2f3, 8lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x8f, 0x9a, 0x80, 0xaa, 0x41 }, 0, true, 0xc15400d0fe9fc2f3, 9lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x8f, 0x9a, 0x80, 0xaa, 0xc1, 0x01 }, 0, true, 0xc15400d0fe9fc2f3, 10lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0xf4, 0x8f, 0x9a, 0x80, 0xaa, 0xc1, 0x62 }, 0, true, 0x415400d0fe9fc2f3, 10lu);
+ // Test with extra trailing numbers
+ testInt64LEBDecode({ 0x07, 0x80 }, 0, true, 0x7, 1lu);
+ testInt64LEBDecode({ 0x07, 0x75 }, 0, true, 0x7, 1lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0x74, 0x43 }, 0, true, 0xfffffffffe9fc2f3, 4lu);
+ testInt64LEBDecode({ 0xf3, 0x85, 0xff, 0x74, 0x80 }, 0, true, 0xfffffffffe9fc2f3, 4lu);
+ // Test with preceeding numbers
+ testInt64LEBDecode({ 0xf3, 0x07 }, 1, true, 0x7, 2lu);
+ testInt64LEBDecode({ 0x03, 0x07 }, 1, true, 0x7, 2lu);
+ testInt64LEBDecode({ 0xf2, 0x53, 0x43, 0x67, 0x79, 0x77 }, 5, true, -0x9, 6lu);
+ testInt64LEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77 }, 5, true, -0x9, 6lu);
+ testInt64LEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02 }, 3, true, 0x82f3, 6lu);
+ // Test in the middle
+ testInt64LEBDecode({ 0xf3, 0x07, 0x89 }, 1, true, 0x7, 2lu);
+ testInt64LEBDecode({ 0x03, 0x07, 0x23 }, 1, true, 0x7, 2lu);
+ testInt64LEBDecode({ 0xf2, 0x53, 0x43, 0x67, 0x79, 0x77, 0x43 }, 5, true, -0x9, 6lu);
+ testInt64LEBDecode({ 0xf2, 0x53, 0x43, 0xf7, 0x84, 0x77, 0xf9 }, 5, true, -0x9, 6lu);
+ testInt64LEBDecode({ 0xf2, 0x53, 0x43, 0xf3, 0x85, 0x02, 0xa4 }, 3, true, 0x82f3, 6lu);
+ // Test decode too long
+ testInt64LEBDecode({ 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }, 0, false, 0x0, 0lu);
+ testInt64LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 1, false, 0x0, 0lu);
+ testInt64LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 0, false, 0x0, 0lu);
+ // Test decode off end of array
+ testInt64LEBDecode({ 0x80, 0x80, 0xab, 0x8a, 0x9a, 0xa3, 0xff }, 2, false, 0x0, 0lu);
+}
+
+
</ins><span class="cx"> } // namespace TestWebKitAPI
</span></span></pre>
</div>
</div>
</body>
</html>