Skip to content

[hl/std] Prevent StringBuf expand overflow - #12990

Open
yuxiaomao wants to merge 2 commits into
HaxeFoundation:developmentfrom
yuxiaomao:dev-hl-stringbuf-exp
Open

[hl/std] Prevent StringBuf expand overflow#12990
yuxiaomao wants to merge 2 commits into
HaxeFoundation:developmentfrom
yuxiaomao:dev-hl-stringbuf-exp

Conversation

@yuxiaomao

Copy link
Copy Markdown
Contributor

The maximum StringBuf size was limited to INT_MAX/3 by the (size* 3) >> 1, this PR allows it to grow up to nearly INT_MAX and throw appropriate exception on too large buffer size.

function main() {
	var bytes = haxe.io.Bytes.alloc(454624961); // ~450 MB
	var hex = bytes.toHex(); // ~900M chars (~1.8 GB), triggers StringBuf expand overflow that result in segfault later
	trace(hex.length);
}

@yuxiaomao

Copy link
Copy Markdown
Contributor Author

FYI @ncannasse (fix for toHex)

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