Skip to content

Limit Date.parse input length and make interruptible#6951

Merged
headius merged 5 commits intojruby:jruby-9.2.20.0from
headius:date_parse_limit
Nov 30, 2021
Merged

Limit Date.parse input length and make interruptible#6951
headius merged 5 commits intojruby:jruby-9.2.20.0from
headius:date_parse_limit

Conversation

@headius
Copy link
Member

@headius headius commented Nov 30, 2021

Excessively long input to the various Date parsing methods can cause the calling thread to run for a long time, perhaps tying it up indefinitely. This PR incorporates to changes similar to those in ruby/date@3959acc.

  • Add a limit option to the affected Date parse methods (see commit above for the list).
  • Make the regexp matches used by these parse methods interruptible.
  • Add the same test as CRuby under our JRuby test suite, since no spec was added by ruby-core and we might not see the CRuby test for a long time (and possibly never on our 9.2 branch).

The interruptibility patch here begs a question: should we just flip the switch and make all regexp matches interruptible all the time? We opted not to do so in jruby/joni#6, but have since reduced the overhead of the interrupt check. It seems like CRuby has made all regexp interruptible all the time, and perhaps we should follow suit. This would eliminate the need for that part of the PR.

A partial workaround for users is to enable interruptible regexp matches with the JRuby property "regexp.interruptible=true" in .jruby_opts, as -Xregexp.interruptible on the command line, or by setting the JVM property jruby.regexp.interruptible=true, and then wrap the Date parsing methods in Timeout (or perhaps your framework will do this for you).

A more complete workaround would be to apply the Ruby changes here to your local JRuby environment. This will not make the matches interruptible, but the default 128 length limit will prevent such large strings from being parsed.

cc @jordansissel, @rsim

enebo and others added 5 commits November 2, 2021 16:15
This prevents extremely long input from tying up the system for
a long time.
This allows the running matches to be interrupted from Ruby, to
avoid them running for an excessive amount of time.
@headius
Copy link
Member Author

headius commented Nov 30, 2021

The lack of testing on the 9.2 branch is a bit of a problem here.

I fixed some failures in Date specs and they are now green.

rake test:jruby and rake test:mri:stdlib also pass (at least as well as they did before).

@headius headius added this to the 9.2.19.1 milestone Nov 30, 2021
@headius
Copy link
Member Author

headius commented Nov 30, 2021

@enebo If we intend this to be in 9.2.19.1 we can make a 9.2.19 branch and I will rebase this.

Ditto for 9.3.1.1, and I will do a separate PR merging 9.2.19.1 over.

@headius headius changed the base branch from jruby-9.2 to jruby-9.2.20.0 November 30, 2021 14:42
@headius headius merged commit 34a168e into jruby:jruby-9.2.20.0 Nov 30, 2021
@headius headius deleted the date_parse_limit branch November 30, 2021 14:44
headius added a commit that referenced this pull request Dec 1, 2021
commit 89e4ee5
Merge: da0c593 bbaf162
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Wed Dec 1 10:16:14 2021 -0600

    Merge pull request #6953 from headius/update_jnr

    Update JNR dependencies

commit bbaf162
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Wed Dec 1 10:12:26 2021 -0600

    Update JNR dependencies

    * jffi to 1.3.8
    * jnr-ffi to 2.2.10
    * jnr-posix to 3.1.13
    * jnr-enxio to 0.32.12
    * jnr-unixsocket to 0.38.14

commit da0c593
Merge: caa52b8 a9f3b6b
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Wed Dec 1 09:39:08 2021 -0600

    Merge branch 'jruby-9.2.20.0' into jruby-9.2

commit a9f3b6b
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Tue Nov 30 10:12:50 2021 -0600

    Exclude broken parse test imported from json

    This test passes to DateTime.parse a keyword argument
    "create_additions" that is unknown to DateTime, but because CRuby
    only checks for the "limit" option it expects, this does not cause
    any error. In JRuby, where we still have this code in Ruby, the
    unknown keyword is explicitly rejected. We exclude this for now
    and will fix the bad test in json lib.

commit 34a168e
Merge: 1a32554 3e1a262
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Tue Nov 30 08:44:32 2021 -0600

    Merge pull request #6951 from headius/date_parse_limit

    Limit Date.parse input length and make interruptible

commit 3e1a262
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Tue Nov 30 03:12:00 2021 -0600

    Match CRuby type conversions here

commit aa5e8eb
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Tue Nov 30 02:21:21 2021 -0600

    Add CRuby's test for Date parse limiting

commit 4a6e676
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Tue Nov 30 02:17:51 2021 -0600

    Make all Date parser regexp calls interruptible

    This allows the running matches to be interrupted from Ruby, to
    avoid them running for an excessive amount of time.

commit af68c6c
Author: Charles Oliver Nutter <headius@headius.com>
Date:   Tue Nov 30 02:16:58 2021 -0600

    Add limit option to Date parse methods

    This prevents extremely long input from tying up the system for
    a long time.
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