You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here's a nice and easy way to cause fish to use lots of CPU and memory while doing nothing of value:
read-l foo </dev/zero
This will (AFAICT) never complete and use as much memory as you give it time to accumulate.
We should limit how much read will accept - something "ridiculously large" in the typical case, like 100M or so, should suffice and not impact people doing things.
Agreed, although I think a lower limit would be fine since fish is the wrong tool for manipulating massive amounts of data. Slurping up even a couple of megabytes in a single read would be an extremely unusual thing to do and likely indicates a bug in the script or that it is reading unexpected data as in the example in the opening comment. However, setting the limit 10 MB rather than 100 MB is unlikely to make fish any "safer" (i.e., unlikely to crash or make your system slow down) so we might as well use the higher limit just in case someone really does want to abuse the shell.
I've changed my mind. A limit of 10 MiB should be an order of magnitude larger than needed for any well behaved script. No shell script should be reading even 10 MiB into a variable. So I don't see any reason to use a limit of 100 MiB.
I think this is the perfect time to implement this since we just released 2.5.0 and have several months before 2.6.0. That should give plenty of time to find out if people are using fish in some crazy fashion that might require a higher limit. Note that many text processing tools have line length limits of 4 KiB or thereabouts. So even a 1 MiB limit would be 256 times that widely used limit.
The one aspect of the change that might be controversial is tossing the results of the read if it exceeds the limit. That isn't something I implemented with the change I'm about to make a PR for. It just happens to be an artifact of how read is currently implemented. We could change that if anyone can make a cogent argument for returning a partial "line" when --nchars wasn't specified.
FWIW, I've decided to make the limit configurable via a FISH_READ_BYTE_LIMIT variable but with a default of 10 MiB. What caused me to make it configurable was noting that the unit tests were taking tens of seconds with the default 10 MiB limit. Setting the limit to 8 KiB lets those tests complete so fast as to be not worth measuring. And making it configurable means that if someone does have an unusual need to read large amounts of data they can do so if they know what they are doing.
Activity
krader1961 commentedon Jan 7, 2017
Agreed, although I think a lower limit would be fine since fish is the wrong tool for manipulating massive amounts of data. Slurping up even a couple of megabytes in a single read would be an extremely unusual thing to do and likely indicates a bug in the script or that it is reading unexpected data as in the example in the opening comment. However, setting the limit 10 MB rather than 100 MB is unlikely to make fish any "safer" (i.e., unlikely to crash or make your system slow down) so we might as well use the higher limit just in case someone really does want to abuse the shell.
krader1961 commentedon Jan 7, 2017
Taking ownership since this is a natural addendum to the
builtin_read()refactoring in PR #3691.krader1961 commentedon Feb 7, 2017
I've changed my mind. A limit of 10 MiB should be an order of magnitude larger than needed for any well behaved script. No shell script should be reading even 10 MiB into a variable. So I don't see any reason to use a limit of 100 MiB.
floam commentedon Feb 8, 2017
I base64-encode my
~tarball every night and store it as a uvar! Will you break this?Joking. Sounds reasonable.
krader1961 commentedon Feb 8, 2017
I think this is the perfect time to implement this since we just released 2.5.0 and have several months before 2.6.0. That should give plenty of time to find out if people are using fish in some crazy fashion that might require a higher limit. Note that many text processing tools have line length limits of 4 KiB or thereabouts. So even a 1 MiB limit would be 256 times that widely used limit.
The one aspect of the change that might be controversial is tossing the results of the read if it exceeds the limit. That isn't something I implemented with the change I'm about to make a PR for. It just happens to be an artifact of how
readis currently implemented. We could change that if anyone can make a cogent argument for returning a partial "line" when--ncharswasn't specified.krader1961 commentedon Feb 10, 2017
FWIW, I've decided to make the limit configurable via a
FISH_READ_BYTE_LIMITvariable but with a default of 10 MiB. What caused me to make it configurable was noting that the unit tests were taking tens of seconds with the default 10 MiB limit. Setting the limit to 8 KiB lets those tests complete so fast as to be not worth measuring. And making it configurable means that if someone does have an unusual need to read large amounts of data they can do so if they know what they are doing.put upper bound on data `read` will consume