Skip to content

Commit

Permalink
max_tree_depth: restrict for MSVC to avoid running into stack overflows
Browse files Browse the repository at this point in the history
There seems to be TBD

In one case, when `traverse_trees_cur_depth` was 562, the following
stack trace shows when that happens:

[0x0]   ntdll!RtlpAllocateHeap+0x31   0x4212603f50   0x7ff9d6d4cd49
[0x1]   ntdll!RtlpAllocateHeapInternal+0x6c9   0x42126041b0   0x7ff9d6e14512
[0x2]   ntdll!RtlDebugAllocateHeap+0x102   0x42126042b0   0x7ff9d6dcd8b0
[0x3]   ntdll!RtlpAllocateHeap+0x7ec70   0x4212604350   0x7ff9d6d4cd49
[0x4]   ntdll!RtlpAllocateHeapInternal+0x6c9   0x42126045b0   0x7ff9596ed480
[0x5]   ucrtbased!heap_alloc_dbg_internal+0x210   0x42126046b0   0x7ff9596ed20d
[0x6]   ucrtbased!heap_alloc_dbg+0x4d   0x4212604750   0x7ff9596f037f
[0x7]   ucrtbased!_malloc_dbg+0x2f   0x42126047a0   0x7ff9596f0dee
[0x8]   ucrtbased!malloc+0x1e   0x42126047d0   0x7ff730fcc1ef
[0x9]   git!do_xmalloc+0x2f   0x4212604800   0x7ff730fcc2b9
[0xa]   git!do_xmallocz+0x59   0x4212604840   0x7ff730fca779
[0xb]   git!xmallocz_gently+0x19   0x4212604880   0x7ff7311b0883
[0xc]   git!unpack_compressed_entry+0x43   0x42126048b0   0x7ff7311ac9a4
[0xd]   git!unpack_entry+0x554   0x42126049a0   0x7ff7311b0628
[0xe]   git!cache_or_unpack_entry+0x58   0x4212605250   0x7ff7311ad3a8
[0xf]   git!packed_object_info+0x98   0x42126052a0   0x7ff7310a92da
[0x10]   git!do_oid_object_info_extended+0x3fa   0x42126053b0   0x7ff7310a44e7
[0x11]   git!oid_object_info_extended+0x37   0x4212605460   0x7ff7310a38ba
[0x12]   git!repo_read_object_file+0x9a   0x42126054a0   0x7ff7310a6147
[0x13]   git!read_object_with_reference+0x97   0x4212605560   0x7ff7310b4656
[0x14]   git!fill_tree_descriptor+0x66   0x4212605620   0x7ff7310dc0a5
[0x15]   git!traverse_trees_recursive+0x3f5   0x4212605680   0x7ff7310dd831
[0x16]   git!unpack_callback+0x441   0x4212605790   0x7ff7310b4c95
[0x17]   git!traverse_trees+0x5d5   0x42126058a0   0x7ff7310dc0f2
[0x18]   git!traverse_trees_recursive+0x442   0x4212605980   0x7ff7310dd831
[0x19]   git!unpack_callback+0x441   0x4212605a90   0x7ff7310b4c95
[0x1a]   git!traverse_trees+0x5d5   0x4212605ba0   0x7ff7310dc0f2
[0x1b]   git!traverse_trees_recursive+0x442   0x4212605c80   0x7ff7310dd831
[0x1c]   git!unpack_callback+0x441   0x4212605d90   0x7ff7310b4c95
[0x1d]   git!traverse_trees+0x5d5   0x4212605ea0   0x7ff7310dc0f2
[0x1e]   git!traverse_trees_recursive+0x442   0x4212605f80   0x7ff7310dd831
[0x1f]   git!unpack_callback+0x441   0x4212606090   0x7ff7310b4c95
[0x20]   git!traverse_trees+0x5d5   0x42126061a0   0x7ff7310dc0f2
[0x21]   git!traverse_trees_recursive+0x442   0x4212606280   0x7ff7310dd831
[...]

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Oct 31, 2023
1 parent 51630e3 commit dbd170a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion environment.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,18 @@ int merge_log_config = -1;
int precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */
unsigned long pack_size_limit_cfg;
enum log_refs_config log_all_ref_updates = LOG_REFS_UNSET;
int max_allowed_tree_depth = 2048;
int max_allowed_tree_depth =
#ifdef _MSC_VER
/*
* Visual C-compiled Git seems to run into internal stack overflow
* detection in the `RtlpAllocateHeap()` function that is called from
* within `git_inflate_init()`'s call tree, unless the following value
* is low enough.
*/
512;
#else
2048;
#endif

#ifndef PROTECT_HFS_DEFAULT
#define PROTECT_HFS_DEFAULT 0
Expand Down

0 comments on commit dbd170a

Please sign in to comment.