-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Heap-buffer-overflow (OSS-Fuzz issue 585) #452
Comments
Observations:
The error seems to be a missing NULL byte. This works std::vector<uint8_t> vec = {'-', '0', '1', '\0'};
char* m_start = reinterpret_cast<char*>(vec.data());
std::strtoll(m_start, nullptr, 10); This does not: std::vector<uint8_t> vec = {'-', '0', '1'};
char* m_start = reinterpret_cast<char*>(vec.data());
std::strtoll(m_start, nullptr, 10); |
Probably need to check for a null byte and either return an error or add it before calling |
Right. I think this is really an edge case which should not be triggered too often. |
It seems I just have to call |
Ok. One fix would be to check if This approach works: all tests (including a regression test for this issue) pass with ASAN. But it is ugly, because (1) the lexer would properly read a number wrt. the JSON specification, (2) the parser would check if the line buffer is empty and refill it (totally the job of the lexer) and then (3) process the number and maybe reading more bytes than the lexer did in (1). I could move the Once we would accept that we always parse from a buffer that we control, we can exploit this and not only add This all may be possible (and is out of scope of this issue), but I am uncomfortable fixing this issue by switching to copying the input buffer in any case. Any ideas? |
Another observation: In the first step when re2c recognizes numbers, it takes care of resizing the buffer if necessary. We only get into troubles if:
The second point can only occur if re2c stops reading a number before So basically, the grammar can be extended to reject such numbers, leaving everything else unchanged. |
Reported as fixed with 973402c. |
Input:
-012274
The text was updated successfully, but these errors were encountered: