Skip to content

Limit read #3712

Closed
Closed

Description

@faho

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.

Activity

  1. added
    docs
    on Jan 7, 2017
  2. added this to the fish-future milestone on Jan 7, 2017
  3. krader1961 commented on Jan 7, 2017

    @krader1961
    Contributor

    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.

  4. krader1961 commented on Jan 7, 2017

    @krader1961
    Contributor

    Taking ownership since this is a natural addendum to the builtin_read() refactoring in PR #3691.

  5. krader1961 commented on Feb 7, 2017

    @krader1961
    Contributor

    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.

  6. floam commented on Feb 8, 2017

    @floam
    Member

    I base64-encode my ~ tarball every night and store it as a uvar! Will you break this?

    Joking. Sounds reasonable.

  7. krader1961 commented on Feb 8, 2017

    @krader1961
    Contributor

    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.

  8. krader1961 commented on Feb 10, 2017

    @krader1961
    Contributor

    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.

  9. modified the milestones: , fish-future on Mar 29, 2017
  10. added a commit that references this issue on Apr 17, 2017
    6d2791a
  11. locked as resolved and limited conversation to collaborators on Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docsenhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions