git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3] fuzz: add new oss-fuzz fuzzer for date.c / date.h

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 14, 2023, 17:03 UTC
Message-ID
<xmqqv8a4xo6g.fsf@gitster.g>
In-Reply-To
<pull.1612.v3.git.1699959186146.gitgitgadget@gmail.com>
"Arthur Chan via GitGitGadget" <gitgitgadget@gmail.com> writes:
>      ++	tmp_data = (int8_t*)data;
>      ++	tz = *tmp_data++;
>      ++	tz = (tz << 8) | *tmp_data++;
>      ++	tz = (tz << 8) | *tmp_data++;

This has a funny skew towards negative number. Any time MSB of the one of the three bytes is set, tz becomes negative. Worse, a byte taken from *tmp_data that has its MSB on will _wipe_ what was read in tz so far, because its higher order bits above 8th bit are sign extended. If the incoming data is evenly distributed, 7/8 of the time, you'd end up with a negative number in tz, no?

I think you can and should pick bytes with uint8_t pointer to avoid sign extending individual bytes and sign extend the resulting number at the end. Or if it is too cumbersome to do so, using "int16_t tz" and filling it with two bytes from *data will sign extend itself when we pass it to show_date() as a parameter of type "int", which may be the easiest to code, I suspect.

Thanks.
Previous: Arthur Chan via GitGitGadgetNext: Arthur Chan via GitGitGadget
Message 9 of 10 in “fuzz: add new oss-fuzz fuzzer for date.c / date.h”
  1. fuzz: add new oss-fuzz fuzzer for date.c / date.hArthur Chan via GitGitGadget, Nov 11, 2023
  2. Junio C HamanoNov 12, 2023
  3. Junio C HamanoNov 12, 2023
  4. fuzz: add new oss-fuzz fuzzer for date.c / date.hArthur Chan via GitGitGadget, Nov 13, 2023
  5. Jeff KingNov 13, 2023
  6. Junio C HamanoNov 13, 2023
  7. Junio C HamanoNov 13, 2023
  8. fuzz: add new oss-fuzz fuzzer for date.c / date.hArthur Chan via GitGitGadget, Nov 14, 2023
  9. Junio C HamanoNov 14, 2023
  10. fuzz: add new oss-fuzz fuzzer for date.c / date.hArthur Chan via GitGitGadget, Nov 17, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.