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

Large argument to RPAD results in std::bad_alloc #610

Closed
mrigger opened this issue May 1, 2020 · 2 comments · Fixed by #611
Closed

Large argument to RPAD results in std::bad_alloc #610

mrigger opened this issue May 1, 2020 · 2 comments · Fixed by #611

Comments

@mrigger
Copy link
Contributor

mrigger commented May 1, 2020

Consider the following statement:

SELECT RPAD('a', 100000000000000000, 0); -- Error: std::bad_alloc

The SELECT results in an error std::bad_alloc, after running for a while. Is this expected? I checked with MySQL, which seems to immediately return NULL for an overly large size argument.

I found this based on commit 11e5161.

@Mytherin
Copy link
Collaborator

Mytherin commented May 1, 2020

Interesting! I tried it in MySQL and the limit seems to be 16777216.

SELECT LENGTH(RPAD('a', 16777216, 0));
-- 16777216
SELECT LENGTH(RPAD('a', 16777217, 0));
-- NULL

Looking at the MySQL source code this value seems to occur in a bunch of places, this seems to be a likely culprit:

#define MAX_BLOB_WIDTH 16777216 /**< Default width for blob */

But then, strangely, this does work:

SELECT LENGTH(CONCAT(RPAD('a', 16777216, 0), RPAD('a', 16777216, 0)));
-- 33554432

Anyway, in this case I think rpad should return an error, as the maximum string size our system can handle is 2^31. I think a better way of solving this would be to turn the second argument into type INTEGER, instead of of type BIGINT. Then values of this size could not be passed to rpad in the first place. A bad_alloc can still potentially occur if the user doesn't have 2GB of memory, but that is then the expected behavior.

@hawkfish
Copy link
Contributor

hawkfish commented May 1, 2020

Yes, assign it to me.

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 a pull request may close this issue.

3 participants