Skip to content

Commit 8377f34

Browse files
committed
Merge branch 'jh/memihash-opt'
Hotfix for a topic that is already in 'master'. * jh/memihash-opt: p0004: make perf test executable t3008: skip lazy-init test on a single-core box test-online-cpus: helper to return cpu count name-hash: fix buffer overrun
2 parents 5feb8b8 + c9d4999 commit 8377f34

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ TEST_PROGRAMS_NEED_X += test-line-buffer
626626
TEST_PROGRAMS_NEED_X += test-match-trees
627627
TEST_PROGRAMS_NEED_X += test-mergesort
628628
TEST_PROGRAMS_NEED_X += test-mktemp
629+
TEST_PROGRAMS_NEED_X += test-online-cpus
629630
TEST_PROGRAMS_NEED_X += test-parse-options
630631
TEST_PROGRAMS_NEED_X += test-path-utils
631632
TEST_PROGRAMS_NEED_X += test-prio-queue

name-hash.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ static int handle_range_dir(
342342
* Scan forward in the index array for index entries having the same
343343
* path prefix (that are also in this directory).
344344
*/
345-
if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0)
345+
if (k_start + 1 >= k_end)
346+
k = k_end;
347+
else if (strncmp(istate->cache[k_start + 1]->name, prefix->buf, prefix->len) > 0)
346348
k = k_start + 1;
347349
else if (strncmp(istate->cache[k_end - 1]->name, prefix->buf, prefix->len) == 0)
348350
k = k_end;

t/helper/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/test-match-trees
1717
/test-mergesort
1818
/test-mktemp
19+
/test-online-cpus
1920
/test-parse-options
2021
/test-path-utils
2122
/test-prio-queue

t/helper/test-online-cpus.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "git-compat-util.h"
2+
#include "thread-utils.h"
3+
4+
int cmd_main(int argc, const char **argv)
5+
{
6+
printf("%d\n", online_cpus());
7+
return 0;
8+
}

t/perf/p0004-lazy-init-name-hash.sh

100644100755
File mode changed.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/sh
2+
3+
test_description='Test the lazy init name hash with various folder structures'
4+
5+
. ./test-lib.sh
6+
7+
if test 1 -eq $($GIT_BUILD_DIR/t/helper/test-online-cpus)
8+
then
9+
skip_all='skipping lazy-init tests, single cpu'
10+
test_done
11+
fi
12+
13+
LAZY_THREAD_COST=2000
14+
15+
test_expect_success 'no buffer overflow in lazy_init_name_hash' '
16+
(
17+
test_seq $LAZY_THREAD_COST | sed "s/^/a_/"
18+
echo b/b/b
19+
test_seq $LAZY_THREAD_COST | sed "s/^/c_/"
20+
test_seq 50 | sed "s/^/d_/" | tr "\n" "/"; echo d
21+
) |
22+
sed "s/^/100644 $EMPTY_BLOB /" |
23+
git update-index --index-info &&
24+
test-lazy-init-name-hash -m
25+
'
26+
27+
test_done

0 commit comments

Comments
 (0)