Skip to content

Commit

Permalink
In case of buffer overflow create an event with a slice of the data a…
Browse files Browse the repository at this point in the history
…nd tag the event with an error
  • Loading branch information
andsel committed Sep 2, 2024
1 parent c928408 commit 907c8ca
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/logstash/codecs/json_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ def decode(data, &block)
@buffer.extract(data).each do |line|
parse_json(@converter.convert(line), &block)
end
rescue java.lang.IllegalStateException => e
if e.message == "input buffer full" && @decode_size_limit_bytes != "none"
yield event_factory.new_event("message" => data[0..@decode_size_limit_bytes.to_i - 1], "tags" => ["_jsonparsetoobigfailure"]) #TODO check the failure tag
else
# re-raise the error if doesn't correspond to the buffer overflow condition
raise e
end
end

def encode(event)
Expand Down
2 changes: 1 addition & 1 deletion spec/codecs/json_lines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@

it "should raise an error if the max bytes are exceeded" do
subject.decode(maximum_payload << "z") do |event|
expect(event.get("tags")).to include("_jsonparse_too_big_failure")
expect(event.get("tags")).to include("_jsonparsetoobigfailure")
expect(event.get("message").size).to eq(decode_size_limit_bytes)
end
end
Expand Down

0 comments on commit 907c8ca

Please sign in to comment.