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

Re: [PATCH 31/31] gitweb: make hash size independent

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Feb 12, 2019, 10:57 UTC
Message-ID
<871s4dl1e7.fsf@evledraar.gmail.com>
In-Reply-To
<20190212012256.1005924-32-sandals@crustytoothpaste.net>
On Tue, Feb 12 2019, brian m. carlson wrote:
Show 10 quoted lines
> Gitweb has several hard-coded 40 values throughout it to check for
> values that are passed in or acquired from Git.  To simplify the code,
> introduce a regex variable that matches either exactly 40 or exactly 64
> hex characters, and use this variable anywhere we would have previously
> hard-coded a 40 in a regex.
>
> Similarly, switch the code that looks for deleted diffinfo information
> to look for either 40 or 64 zeros, and update one piece of code to use
> this function.  Finally, when formatting a log line, allow an
> abbreviated describe output to contain up to 64 characters.

This might be going a bit overboard but I tried this with a variant where...

> +# A regex matching a valid object ID.
> +our $oid_regex = qr/(?:[0-9a-fA-F]{40}(?:[0-9a-fA-F]{24})?)/;
> +
Instead of this dense regex I did:
    my $sha1_len = 40;
    my $sha256_extra_len = 24;
    my $sha256_len = $sha1_len + $sha256_extra_len;
    sub oid_nlen_regex {
    	my $len = shift;
    	my $hchr = qr/[0-9a-fA-F]/;
    	return qr/(?:(?:$hchr){$len})/
    }
    our $oid_regex;
    {
        my $x = oid_nlen_regex($sha1_len);
        my $y = oid_nlen_regex($sha256_extra_len);
        $oid_regex = qr/(?:$x(?:$y)?)/
    }
Then most of the rest of this is the same, e.g.:
> -	if ($input =~ m/^[0-9a-fA-F]{40}$/) {
But...
Show 13 quoted lines
> @@ -2037,10 +2040,10 @@ sub format_log_line_html {
>              (?<!-) # see strbuf_check_tag_ref(). Tags can't start with -
>              [A-Za-z0-9.-]+
>              (?!\.) # refs can't end with ".", see check_refname_format()
> -            -g[0-9a-fA-F]{7,40}
> +            -g[0-9a-fA-F]{7,64}
>              |
>              # Just a normal looking Git SHA1
> -            [0-9a-fA-F]{7,40}
> +            [0-9a-fA-F]{7,64}
>          )
>          \b
>      }{
E.g. here we can do call oid_nlen_regex("7,64") to produce this blurb.
> -	if ($line =~ m/^index [0-9a-fA-F]{40},[0-9a-fA-F]{40}/) {
> +	if ($line =~ m/^index $oid_regex,$oid_regex/) {
> -	} elsif ($line =~ m/^index [0-9a-fA-F]{40}..[0-9a-fA-F]{40}/) {
> +	} elsif ($line =~ m/^index $oid_regex..$oid_regex/) {

And here, maybe nobody cares, but we now implicitly accept mixed SHA-1 & SHA-256 input. Whereas we could have a helper on top of the above code like:

    sub oid_nlen_prefix_infix_regex {
        my $nlen = shift;
        my $prefix = shift;
        my $infix = shift;
        my $rx = oid_nlen_regex($nlen);
        return qr/^\Q$prefix\E$rx\Q$infix\E$rx$/;
    }
And then e.g.:
    } elsif ($line =~ oid_nlen_prefix_infix_regex($sha1_len, "index ", "..") ||
             $line =~ oid_nlen_prefix_infix_regex($sha256_len, "index ", "..")) {

So only accept SHA1..SHA1 or SHA256..SHA256, not SHA1..SHA256 or SHA256..SHA1.

Previous: brian m. carlsonNext: brian m. carlson
Message 44 of 56 in “Hash function transition part 16”
  1. 00/31 Hash function transition part 16brian m. carlson, Feb 12, 2019
  2. 01/31 t/lib-submodule-update: use appropriate length constantbrian m. carlson, Feb 12, 2019
  3. 03/31 pack-bitmap: convert struct stored_bitmap to object_idbrian m. carlson, Feb 12, 2019
  4. 02/31 pack-bitmap: make bitmap header handling hash agnosticbrian m. carlson, Feb 12, 2019
  5. 05/31 pack-bitmap: switch hard-coded constants to the_hash_algobrian m. carlson, Feb 12, 2019
  6. Ævar Arnfjörð BjarmasonFeb 12, 2019
  7. 04/31 pack-bitmap: replace sha1_to_hexbrian m. carlson, Feb 12, 2019
  8. Jeff KingFeb 12, 2019
  9. brian m. carlsonFeb 13, 2019
  10. Jeff KingFeb 14, 2019
  11. 08/31 notes: make hash size independentbrian m. carlson, Feb 12, 2019
  12. Eric SunshineFeb 12, 2019
  13. brian m. carlsonFeb 12, 2019
  14. 09/31 notes: replace sha1_to_hexbrian m. carlson, Feb 12, 2019
  15. 11/31 builtin/name-rev: make hash-size independentbrian m. carlson, Feb 12, 2019
  16. 06/31 submodule: avoid hard-coded constantsbrian m. carlson, Feb 12, 2019
  17. 10/31 object-store: rename and expand packed_git's sha1 memberbrian m. carlson, Feb 12, 2019
  18. Eric SunshineFeb 12, 2019
  19. brian m. carlsonFeb 14, 2019
  20. 14/31 builtin/am: make hash size independentbrian m. carlson, Feb 12, 2019
  21. 15/31 builtin/pull: make hash-size independentbrian m. carlson, Feb 12, 2019
  22. Eric SunshineFeb 12, 2019
  23. 13/31 fast-import: replace sha1_to_hexbrian m. carlson, Feb 12, 2019
  24. 17/31 http-backend: allow 64-character hex namesbrian m. carlson, Feb 12, 2019
  25. 16/31 http-push: convert to use the_hash_algobrian m. carlson, Feb 12, 2019
  26. 12/31 fast-import: make hash-size independentbrian m. carlson, Feb 12, 2019
  27. Eric SunshineFeb 12, 2019
  28. brian m. carlsonFeb 12, 2019
  29. 18/31 http-push: remove remaining uses of sha1_to_hexbrian m. carlson, Feb 12, 2019
  30. 20/31 http: replace hard-coded constant with the_hash_algobrian m. carlson, Feb 12, 2019
  31. 22/31 http: replace sha1_to_hexbrian m. carlson, Feb 12, 2019
  32. 21/31 http: compute hash of downloaded objects using the_hash_algobrian m. carlson, Feb 12, 2019
  33. 23/31 remote-curl: make hash size independentbrian m. carlson, Feb 12, 2019
  34. Ævar Arnfjörð BjarmasonFeb 12, 2019
  35. 19/31 http-walker: replace sha1_to_hexbrian m. carlson, Feb 12, 2019
  36. Eric SunshineFeb 12, 2019
  37. 29/31 read-cache: read data in a hash-independent waybrian m. carlson, Feb 12, 2019
  38. 28/31 dir: make untracked cache extension hash size independentbrian m. carlson, Feb 12, 2019
  39. Ævar Arnfjörð BjarmasonFeb 12, 2019
  40. brian m. carlsonFeb 13, 2019
  41. 25/31 archive: convert struct archiver_args to object_idbrian m. carlson, Feb 12, 2019
  42. 26/31 refspec: make hash size independentbrian m. carlson, Feb 12, 2019
  43. 31/31 gitweb: make hash size independentbrian m. carlson, Feb 12, 2019
  44. Ævar Arnfjörð BjarmasonFeb 12, 2019
  45. 30/31 Git.pm: make hash size independentbrian m. carlson, Feb 12, 2019
  46. Ævar Arnfjörð BjarmasonFeb 12, 2019
  47. brian m. carlsonFeb 18, 2019
  48. Ævar Arnfjörð BjarmasonFeb 18, 2019
  49. 24/31 archive-tar: make hash size independentbrian m. carlson, Feb 12, 2019
  50. René ScharfeFeb 12, 2019
  51. René ScharfeFeb 12, 2019
  52. brian m. carlsonFeb 13, 2019
  53. 27/31 builtin/difftool: use parse_oid_hexbrian m. carlson, Feb 12, 2019
  54. Eric SunshineFeb 12, 2019
  55. 07/31 notes-merge: switch to use the_hash_algobrian m. carlson, Feb 12, 2019
  56. Ævar Arnfjörð BjarmasonFeb 12, 2019

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.