Skip to content

Commit

Permalink
Fix parser eof (#927)
Browse files Browse the repository at this point in the history
* Fix EOF issue in Oj::Parser
  • Loading branch information
ohler55 authored Jun 8, 2024
1 parent 2d2109b commit 2e57dc7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
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

0 comments on commit 2e57dc7

Please sign in to comment.