-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Floating point numbers cause a memory error #47935
Comments
@TheAndrey brick math is required because PHP cannot natively handle large float values. With Brick math in place, we can perform validation against these larger numbers that PHP cannot natively handle. I would recommend using something like a |
How do I disable the use of this library? This only creates problems. I don't need to work with large numbers. @timacdonald you have very skillfully shown the absence of error, showed examples on relatively small numbers. I don't see a solution to the application attack problem yet. Hackers will definitely use this error for a DoS attack. I found commits in which a third-party library was added. Their rollback solves my problem. Why were these changes made? Work with the extension can be made optional by checking it with |
Hey @TheAndrey, This library was introduced as PHP cannot handle arbitrarily large numbers. The number you are working with, for example, is cast to php -r "var_dump(floatval('10.9e-10000000000') === 0.0);"
// true For now, I would recommend using a regex rule in conjunction with the If you do not want to support scientific notation input, once #47954 is merged I would recommend using something like: "bail|required|decimal:0,5" I also have a follow up PR that will extend the This will allow you to limit the precision and overall size of the number in length. "bail|required|decimal:0,5|max_digits:10" I'll reopen this issue until we have both of these PRs merged. |
I know that PHP does not know how to work with large numbers. This programming language is not suitable for scientific computing.
Usually, rules are often set to the minimum value, this is a positive number. What does it matter what the original number was if after the conversion, taking into the limitations of PHP, it can pass the validation rule? It looks incorrect in relation to the user when the number has changed, but at the same time the user does not have the opportunity to go beyond the acceptable values. The |
This proposed validation rule will allow you to limit the length of a decimal: #47976 With this in place, you should be able to configure the rules to suit your system and avoid the memory issues you were hitting. I have added unit tests to ensure that scientific notation is not accepted by the decimal rule. Thanks for reporting this, @TheAndrey. |
Laravel Version
10.16.1
PHP Version
8.1.21
Database Driver & Version
Ver 15.1 Distrib 10.5.11-MariaDB, for Win64 (AMD64)
Description
I made a form in which present a field for entering the amount. During testing, it turned out that entering very large values as 10.9e-10000000000 leads to the error of exhausting the PHP memory limit.
I did the validation as follows:
I tried changing the rule to
decimal:0,2
andinteger
and it doesn't help. The restriction on the length of the string using themax:
rule stops working when there are rules for validating numbers in the chain.What should I do to prevent validator from trying to convert a string to a large number? 😞
My application is supposed to work with small numbers that fits into the size of a regular float. I don't need
BigDecimal
at all.I have never had such problems with pure PHP...
$ php -dmemory_limit=2M -r "var_dump(floatval('10.9e-10000000000'));"
Steps To Reproduce
min
,max
,between
.10.9e-10000000000
).The text was updated successfully, but these errors were encountered: