]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commit
test/osd: fix buffer alignment issue in unittest_ecbackend 66849/head
authorKefu Chai <k.chai@proxmox.com>
Fri, 9 Jan 2026 01:25:28 +0000 (09:25 +0800)
committerKefu Chai <k.chai@proxmox.com>
Fri, 9 Jan 2026 04:03:05 +0000 (12:03 +0800)
commit915a071c90f46b7be94d21e63556e0d2f8bd2c9b
tree121c4338e060ce004d6112718d00822a7d9eb3fe
parent533f2c7f72f9f3eac10fc4b43b68992e61e01b50
test/osd: fix buffer alignment issue in unittest_ecbackend

The create_buf() function in TestECBackend.cc had two issues that
caused test failures when running with ASan enabled:

1. Infinite loop potential: When std::rand() % 5 returned 0, len_to_add
   would be 0, causing an infinite loop if the buffer hadn't reached
   the target length yet.

2. Memory alignment issue: Using append_zero() doesn't guarantee that
   the resulting buffer's memory address is aligned to EC_ALIGN_SIZE
   (4096 bytes). The is_aligned() check verifies that all buffers in
   the bufferlist have their data pointers properly aligned, not just
   that the length is a multiple of the alignment size.

Fix by:
- Changing std::rand() % 5 to std::rand() % 5 + 1 to ensure we always
  allocate 1-5 pages worth of data, avoiding the infinite loop
- Replacing append_zero() with buffer::create_page_aligned() followed
  by memset() and append(), which ensures each buffer has its data
  pointer aligned to page boundaries (4096 bytes)

This ensures the test passes consistently with ASan enabled.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/test/osd/TestECBackend.cc