Skip to content

Size limit bytes #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 3.2.0
- Add decode_size_limit_bytes option to limit the maximum size of each JSON line that can be parsed.[#43](https://github.com/logstash-plugins/logstash-codec-json_lines/pull/43)

## 3.1.0
- Feat: event `target => namespace` support (ECS) [#41](https://github.com/logstash-plugins/logstash-codec-json_lines/pull/41)
- Refactor: dropped support for old Logstash versions (< 6.0)
Expand Down
7 changes: 6 additions & 1 deletion lib/logstash/codecs/json_lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base
# Change the delimiter that separates lines
config :delimiter, :validate => :string, :default => "\n"

# Maximum number of bytes for a single line before a fatal exception is raised
# which will stop Logsash.
# The default is 20MB which is quite large for a JSON document
config :decode_size_limit_bytes, :validate => :number, :default => 20 * (1024 * 1024) # 20MB

# Defines a target field for placing decoded fields.
# If this setting is omitted, data gets stored at the root (top level) of the event.
# The target is only relevant while decoding data into a new event.
Expand All @@ -50,7 +55,7 @@ class LogStash::Codecs::JSONLines < LogStash::Codecs::Base
public

def register
@buffer = FileWatch::BufferedTokenizer.new(@delimiter)
@buffer = FileWatch::BufferedTokenizer.new(@delimiter, @decode_size_limit_bytes)
@converter = LogStash::Util::Charset.new(@charset)
@converter.logger = @logger
end
Expand Down
2 changes: 1 addition & 1 deletion logstash-codec-json_lines.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-codec-json_lines'
s.version = '3.1.0'
s.version = '3.2.0'
s.licenses = ['Apache License (2.0)']
s.summary = "Reads and writes newline-delimited JSON"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down
16 changes: 16 additions & 0 deletions spec/codecs/json_lines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@
end
end

describe "decode_size_limits_bytes" do
let(:maximum_payload) { "a" * subject.decode_size_limit_bytes }

it "should not raise an error if the number of bytes is not exceeded" do
expect {
subject.decode(maximum_payload)
}.not_to raise_error
end

it "should raise an error if the max bytes are exceeded" do
expect {
subject.decode(maximum_payload << "z")
}.to raise_error(java.lang.IllegalStateException, "input buffer full")
end
end

end

context "#encode" do
Expand Down