Skip to content

Fix C binding empty byte buffers#7807

Open
fallintoplace wants to merge 1 commit into
apache:mainfrom
fallintoplace:fix-c-empty-bytes-buffer
Open

Fix C binding empty byte buffers#7807
fallintoplace wants to merge 1 commit into
apache:mainfrom
fallintoplace:fix-c-empty-bytes-buffer

Conversation

@fallintoplace

Copy link
Copy Markdown

Summary

  • Handle empty C opendal_bytes without constructing a Rust slice from a null pointer.
  • Return an OpenDAL error when non-empty input buffers have null data.
  • Clarify C byte buffer ownership docs and add focused coverage for operator and writer writes.

Why

C callers can reasonably pass { .data = NULL, .len = 0, .capacity = 0 } for an empty buffer. Rust still requires slice::from_raw_parts to receive a non-null, aligned pointer even when the length is zero, so the old conversion could invoke undefined behavior.

Tests

  • cargo clippy -- -D warnings
  • cmake -S . -B build -DTEST_ENABLE_ASAN=ON -DFEATURES=opendal/services-memory && cmake --build build -j4 && ./build/tests
  • cargo build --features="opendal/services-memory" && make -C tests clean all && OPENDAL_TEST=memory make -C tests behavior_test

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. releases-note/fix The PR fixes a bug or has a title that begins with "fix" labels Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

releases-note/fix The PR fixes a bug or has a title that begins with "fix" size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant