Skip to content

Avoid zero-length memory copies with null array or string data - #9200

Open
dand-oss wants to merge 1 commit into
FirebirdSQL:masterfrom
dand-oss:fix/empty-memory-copies
Open

dand-oss wants to merge 1 commit into
FirebirdSQL:masterfrom
dand-oss:fix/empty-memory-copies

Conversation

@dand-oss

@dand-oss dand-oss commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Skip memcpy/memmove when the relevant element count is zero in Array copy/insert/growth operations and when AbstractString is constructed from an empty buffer. Empty dynamically allocated arrays can have null storage, which UBSan diagnoses even when the memory-operation length is zero. Preserve count updates and nonempty operations.

This is a fresh proposal related to the closed #8848. It also covers empty-capacity growth and the length/data AbstractString constructor. The adaptation to current master retains the newer static_cast<void*> destinations and allocator signatures.

Validation on Linux x86-64 with Clang 21 / C++20 / -fsanitize=undefined -fno-sanitize-recover=all:

  • A focused harness instantiates the actual production Array header with a malloc-backed test storage policy, independently of Firebird's global memory-pool startup.
  • Unpatched master fails on empty copy construction, empty-array insertion, null-pointer/zero-count insertion, growing an empty array, and initial growth in a nonempty-operation sequence.
  • All five cases pass with the patch, including checks of resulting counts/content after insertion and assignment.
  • git diff --check passes.

The isolated harness does not cover Firebird's memory-pool lifecycle. The AbstractString runtime case and a complete patched server build have not yet been completed locally.

Skip zero-length memcpy/memmove calls in AbstractString construction and Array copy, insert, and capacity growth operations. Assert that nonempty Array storage is valid before copying during capacity growth.
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.

1 participant