Skip to content

Clear residual buffer chars in TextStringBuilder shrink and clear paths#746

Merged
garydgregory merged 2 commits into
apache:masterfrom
dxbjavid:clear-textstringbuilder-buffer-tail
Jun 2, 2026
Merged

Clear residual buffer chars in TextStringBuilder shrink and clear paths#746
garydgregory merged 2 commits into
apache:masterfrom
dxbjavid:clear-textstringbuilder-buffer-tail

Conversation

@dxbjavid

@dxbjavid dxbjavid commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

TextStringBuilder.clear(), deleteImpl(), the replaceImpl() shrink branch, and setLength(int) all lower the logical size without wiping the now-unused tail of the internal char[], which stays readable through serialization (the buffer is non-transient) and through readFrom() handing the raw array to a Readable. This ports the same fill-with-NUL hardening already merged for StrBuilder in #741, #742, and #744 to its non-deprecated counterpart.

@garydgregory

garydgregory commented Jun 1, 2026

Copy link
Copy Markdown
Member

Hello @dxbjavid
You're missing a unit test(s) to validate this change. See also the API calls to clear buffers in StrBuilder.
TY.

@dxbjavid

dxbjavid commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Added TextStringBuilderClearTest, modeled on StrBuilderClearTest. Covers clear, delete, the replace shrink branch, and setLength, plus the readFrom(Reader) and serialization leak paths. All six tail-clearing cases fail on the unpatched buffer and pass with the fix.

@garydgregory garydgregory changed the title clear residual buffer chars in TextStringBuilder shrink and clear paths Clear residual buffer chars in TextStringBuilder shrink and clear paths Jun 2, 2026
@garydgregory garydgregory merged commit 6f2a032 into apache:master Jun 2, 2026
9 checks passed
* A Reader that, upon reading, inspects the char array it has been given access to (positions beyond offset+len that may contain stale data), records them,
* then supplies its normal data.
*/
static class SpyReader extends Reader {

@garydgregory garydgregory Jun 2, 2026

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.

In the future, reduce the copy pasta please, you've already added this class in a previous PR.

See c6d867e

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.

2 participants