Skip to content

Commit

Permalink
Fix EOF issue in Oj::Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ohler55 committed Jun 8, 2024
1 parent 2d2109b commit 036be24
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 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 - unreleased

- 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
11 changes: 7 additions & 4 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 @@ -1390,10 +1387,16 @@ static VALUE load(VALUE self) {

p->start(p);
while (true) {
rb_funcall(p->reader, oj_readpartial_id, 2, INT2NUM(16385), rbuf);
rb_funcall(p->reader, oj_readpartial_id, 2, INT2NUM(16385), rbuf);
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 036be24

Please sign in to comment.