Skip to content

fix: avoid null pointers in zero-length memory copies - #514

Merged
SteNicholas merged 2 commits into
apache:mainfrom
lxy-9602:fix-slice-ub
Nov 5, 2026
Merged

SteNicholas merged 2 commits into
apache:mainfrom
lxy-9602:fix-slice-ub

Conversation

@lxy-9602

@lxy-9602 lxy-9602 commented Nov 5, 2026

Copy link
Copy Markdown
Member

Purpose

Empty string keys trigger UBSan reports when MemorySlice::CopyBytes() passes null pointers to memcpy, even when the copy length is zero.

Skip zero-length copies in:

  • MemorySlice::CopyBytes()
  • MemorySegment::GetOrCreateHeapMemory()
  • Both ByteArrayInputStream::Read() overloads

Tests

Added regression coverage:

  • MemorySliceTest.TestSliceCopyEmptyBytes
  • MemorySegmentTest.TestGetOrCreateHeapMemoryForEmptySegment
  • ByteArrayInputStreamTest.TestZeroLengthRead
  • ByteArrayInputStreamTest.TestZeroLengthReadFromEmptyStream

API and Format

Documentation

Generative AI tooling

Generated-by: OpenAI Codex (GPT-6)

@lucasfang lucasfang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@SteNicholas SteNicholas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@SteNicholas SteNicholas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@SteNicholas
SteNicholas merged commit fdad861 into apache:main Nov 5, 2026
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants