From dba4be01ab3c892cf0f83cc4f56844e8af49ba7e Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 15 Jun 2017 10:25:42 -0700 Subject: [PATCH] Fix parsing chunk size with leading zeroes fix #496 --- CHANGELOG.md | 1 + include/beast/http/detail/basic_parser.hpp | 2 +- test/http/basic_parser.cpp | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7547828..122506bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Version 58: * basic_parser::put doc * Use static string in basic_fields::reader * Remove redundant code +* Fix parsing chunk size with leading zeroes API Changes: diff --git a/include/beast/http/detail/basic_parser.hpp b/include/beast/http/detail/basic_parser.hpp index d78fff10..beabf2ea 100644 --- a/include/beast/http/detail/basic_parser.hpp +++ b/include/beast/http/detail/basic_parser.hpp @@ -267,7 +267,7 @@ protected: break; auto const v0 = v; v = 16 * v + d; - if(v <= v0) + if(v < v0) return false; } return true; diff --git a/test/http/basic_parser.cpp b/test/http/basic_parser.cpp index 3e3ff15f..10bbe4a7 100644 --- a/test/http/basic_parser.cpp +++ b/test/http/basic_parser.cpp @@ -1054,6 +1054,24 @@ public: }); } + // https://github.com/vinniefalco/Beast/issues/496 + void + testIssue496() + { + // The bug affected hex parsing with leading zeroes + bufgrind>( + "HTTP/1.1 200 OK\r\n" + "Transfer-Encoding: chunked\r\n" + "Content-Type: application/octet-stream\r\n" + "\r\n" + "0004\r\nabcd\r\n" + "0\r\n\r\n" + ,[&](test_parser const& p) + { + BEAST_EXPECT(p.body == "abcd"); + }); + } + //-------------------------------------------------------------------------- void @@ -1072,6 +1090,7 @@ public: testSplit(); testIssue430(); testIssue452(); + testIssue496(); testBufGrind(); } };