Skip to content

Guard mirrored directory name allocation size#4695

Open
Rohithmatham12 wants to merge 1 commit into
facebook:devfrom
Rohithmatham12:fix-mirror-dir-size-overflow
Open

Guard mirrored directory name allocation size#4695
Rohithmatham12 wants to merge 1 commit into
facebook:devfrom
Rohithmatham12:fix-mirror-dir-size-overflow

Conversation

@Rohithmatham12

Copy link
Copy Markdown

Fixes #4642.

mallocAndJoin2Dir() allocated dir1Size + dir2Size + 2 bytes without checking whether the size calculation wrapped. If the sum overflowed size_t, malloc() could receive a buffer size smaller than the later memcpy() calls require.

This adds explicit checked arithmetic before forming the allocation size, preserving the existing fatal CONTROL() behavior for impossible allocation-size failures while preventing the wrapped allocation.

Test plan:

  • make -j4 zstd
  • ZSTD_BIN=../../programs/zstd ./cli-tests/file-handling/directory-mirror.sh
  • git diff --check

@meta-cla meta-cla Bot added the CLA Signed label Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

这个是整数溢出的问题(Integer Overflow Vulnerability) util.c mallocAndJoin2Dir

1 participant