Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check result of repeat/concat fit in an MVMString #546

Conversation

MasterDuke17
Copy link
Contributor

NQP passes make m-test and Rakudo passes make m-spectest.

Fixes https://rt.perl.org/Ticket/Display.html?id=127971

@@ -509,6 +518,13 @@ MVMString * MVM_string_repeat(MVMThreadContext *tc, MVMString *a, MVMint64 count
if (agraphs == 0)
return tc->instance->str_consts.empty;

/* Total size of the resulting string can't be bigger than an MVMString is allowed to be. */
total_graphs = (MVMuint64)agraphs * (MVMuint64)count;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since count is a 64-bit integer, it's possible that this bounds check itself could overflow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agraphs can't be greater than 0xFFFFFFFF (since num_graphs is a MVMuint32) and we already check that count is not greater than (1 << 30). Should be fine, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed the earlier check on count. Then yeah, this is safe. 👍

@jnthn jnthn merged commit dc40845 into MoarVM:master Mar 8, 2017
@MasterDuke17 MasterDuke17 deleted the add_checks_on_resulting_size_to_string_concatenating_and_repeating branch March 8, 2017 22:35
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