-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make DynArray support objects larger than 1 gigabyte
The expression ``const int newAllocated = cap * 2;`` easily causes overflow, as soon as the input is 1.0 GiB. This goes unnoticed because release builds of tinyxml2 do not have active assertions. The change in commit 9.0.0-20-g8fd6cc6 did not do anything useful; the signed multiplication overflow (and thus undefined behavior) still occurs. Using ``int`` in this class is really archaic, because it limits the class to a gigabyte even on 64-bit platforms. The multiplication overflow check also needs to include sizeof(T), otherwise you can run into unsigned multiplication overflow (defined, but undesirable) in the memcpy() call. testcase: int main() { tinyxml2::XMLDocument doc; doc.InsertEndChild(doc.NewDeclaration()); auto root = doc.NewElement("root"); size_t sz = 0x80000001; auto blank = new char[sz]; memset(blank, ' ', sz); blank[sz-1]='\0'; root->SetText(blank); doc.InsertEndChild(root); tinyxml2::XMLPrinter printer(nullptr); doc.Print(&printer); }
- Loading branch information
Showing
2 changed files
with
33 additions
and
34 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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