Skip to content
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

Fix parser eof #927

Merged
merged 3 commits into from
Jun 8, 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 3.16.4 - 2024-06-08

- Fixed Oj::Parse EOF issue on larger stream input.

## 3.16.3 - 2023-12-11

- Fixed the gemspec to allow earlier versions of the bigdecimal gem.
Expand Down
2 changes: 2 additions & 0 deletions ext/oj/oj.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ID oj_as_json_id;
ID oj_begin_id;
ID oj_bigdecimal_id;
ID oj_end_id;
ID oj_eofq_id;
ID oj_exclude_end_id;
ID oj_error_id;
ID oj_file_id;
Expand Down Expand Up @@ -1849,6 +1850,7 @@ void Init_oj(void) {
oj_begin_id = rb_intern("begin");
oj_bigdecimal_id = rb_intern("BigDecimal");
oj_end_id = rb_intern("end");
oj_eofq_id = rb_intern("eof?");
oj_error_id = rb_intern("error");
oj_exclude_end_id = rb_intern("exclude_end?");
oj_file_id = rb_intern("file?");
Expand Down
1 change: 1 addition & 0 deletions ext/oj/oj.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ extern ID oj_as_json_id;
extern ID oj_begin_id;
extern ID oj_bigdecimal_id;
extern ID oj_end_id;
extern ID oj_eofq_id;
extern ID oj_error_id;
extern ID oj_exclude_end_id;
extern ID oj_file_id;
Expand Down
9 changes: 6 additions & 3 deletions ext/oj/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,9 +1114,6 @@ static void parse(ojParser p, const byte *json) {
p->map = trail_map;
}
}
if (0 < p->depth) {
parse_error(p, "parse error, not closed");
}
if (0 == p->depth) {
switch (p->map[256]) {
case '0':
Expand Down Expand Up @@ -1394,6 +1391,12 @@ static VALUE load(VALUE self) {
if (0 < RSTRING_LEN(rbuf)) {
parse(p, (byte *)StringValuePtr(rbuf));
}
if (Qtrue == rb_funcall(p->reader, oj_eofq_id, 0)) {
if (0 < p->depth) {
parse_error(p, "parse error, not closed");
}
break;
}
}
return Qtrue;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/oj/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Oj
# Current version of the module.
VERSION = '3.16.3'
VERSION = '3.16.4'
end