Allow io_memory_resize to truncate to 0 bytes ##io#25706
Open
Allow io_memory_resize to truncate to 0 bytes ##io#25706
Conversation
The TODO asked why truncation to 0 bytes was not allowed. There was no fundamental reason - we just need to free the buffer and reset size/offset instead of calling realloc(ptr, 0) which has implementation-defined behavior. Also add a NULL guard for the RIOMalloc pointer and protect the read path from calling memcpy with a NULL source when the buffer is empty. https://claude.ai/code/session_01H9JNeHBKZngDR8pf47GeH4
Follow-up to the io_memory_resize fix: audit and fix all IO plugins for safe behavior when buffer size is zero. - io_gzip: allow resize to 0 (free buf, reset size/offset) for consistency with io_memory_resize, and guard __read memcpy when count adjusts to 0 to avoid memcpy with NULL source - io_null: fix unsigned underflow in __lseek where size-1 wraps to UT64_MAX when size is 0 (the __resize handler already supported count=0 but __lseek did not) - io_xattr: guard __close to skip write_xattr when buf is NULL after a resize to 0, avoiding passing NULL to setxattr https://claude.ai/code/session_01H9JNeHBKZngDR8pf47GeH4
Fix io_malloc __resize to guard against calling r_hex_bin2strdup with NULL buf/zero size after resize to 0 on hex:// URIs. The assertion in r_hex_bin2strdup would crash the process. Now the URI is set to "hex://" for empty buffers. Add test/db/cmd/cmd_or with 8 tests covering: - resize malloc:// to zero (reads return 0xff) - resize to zero and grow back (buffer is zeroed) - write after resize-to-zero and grow back - shrink preserves partial data - shrink + grow preserves partial data, new area zeroed - map removal after resize to zero - seek behavior after resize to zero - hex:// resize to zero and back https://claude.ai/code/session_01H9JNeHBKZngDR8pf47GeH4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The TODO asked why truncation to 0 bytes was not allowed. There was no
fundamental reason - we just need to free the buffer and reset size/offset
instead of calling realloc(ptr, 0) which has implementation-defined behavior.
Also add a NULL guard for the RIOMalloc pointer and protect the read path
from calling memcpy with a NULL source when the buffer is empty.
https://claude.ai/code/session_01H9JNeHBKZngDR8pf47GeH4