ohler55 / oj

Optimized JSON
http://www.ohler.com/oj
MIT License
3.14k stars 251 forks source link

3.13.17 - Oj.load method takes cpu to 100% and doesn't return on malformed JSON strings #839

Closed martinwaite closed 1 year ago

martinwaite commented 1 year ago

I hit this problem in recent versions of td-agent. Using the tail component with the Oj parser caused fluentd to become unresponsive when it encountered certain lines in a file - and not even ctrl-C could stop it.

The following case causes irb to become unresponsive and cpu to climb:

require 'oj'
s = "{\"f1\":\"data\\nW\x0\"}\r\n"
j = Oj.load(s)

I tested this on newer versions up 3.13.23 and 3.14.0 (to the best of my ability), and it seems the problem is in these versions too.

This was tested on a td-agent 4.4.2 environment ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [x86_64-linux]

ohler55 commented 1 year ago

I'll take a look this evening and see if the illegal character sequence is causing the issue. I would expect an error to be raised.

ohler55 commented 1 year ago

Please try the develop branch. It has a fix.

martinwaite commented 1 year ago

Thanks - the Develop version has fixed the problem.

I installed it in td-agent to test it against the datafile that hit the problem, and the file is completely processed with fluentd reporting errors for lines with malformed JSON - as expected.