Skip to content

Commit 2e57dc7

Browse files
authored
Fix parser eof (#927)
* Fix EOF issue in Oj::Parser
1 parent 2d2109b commit 2e57dc7

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 3.16.4 - 2024-06-08
4+
5+
- Fixed Oj::Parse EOF issue on larger stream input.
6+
37
## 3.16.3 - 2023-12-11
48

59
- Fixed the gemspec to allow earlier versions of the bigdecimal gem.

ext/oj/oj.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ID oj_as_json_id;
3636
ID oj_begin_id;
3737
ID oj_bigdecimal_id;
3838
ID oj_end_id;
39+
ID oj_eofq_id;
3940
ID oj_exclude_end_id;
4041
ID oj_error_id;
4142
ID oj_file_id;
@@ -1849,6 +1850,7 @@ void Init_oj(void) {
18491850
oj_begin_id = rb_intern("begin");
18501851
oj_bigdecimal_id = rb_intern("BigDecimal");
18511852
oj_end_id = rb_intern("end");
1853+
oj_eofq_id = rb_intern("eof?");
18521854
oj_error_id = rb_intern("error");
18531855
oj_exclude_end_id = rb_intern("exclude_end?");
18541856
oj_file_id = rb_intern("file?");

ext/oj/oj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ extern ID oj_as_json_id;
334334
extern ID oj_begin_id;
335335
extern ID oj_bigdecimal_id;
336336
extern ID oj_end_id;
337+
extern ID oj_eofq_id;
337338
extern ID oj_error_id;
338339
extern ID oj_exclude_end_id;
339340
extern ID oj_file_id;

ext/oj/parser.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,9 +1114,6 @@ static void parse(ojParser p, const byte *json) {
11141114
p->map = trail_map;
11151115
}
11161116
}
1117-
if (0 < p->depth) {
1118-
parse_error(p, "parse error, not closed");
1119-
}
11201117
if (0 == p->depth) {
11211118
switch (p->map[256]) {
11221119
case '0':
@@ -1394,6 +1391,12 @@ static VALUE load(VALUE self) {
13941391
if (0 < RSTRING_LEN(rbuf)) {
13951392
parse(p, (byte *)StringValuePtr(rbuf));
13961393
}
1394+
if (Qtrue == rb_funcall(p->reader, oj_eofq_id, 0)) {
1395+
if (0 < p->depth) {
1396+
parse_error(p, "parse error, not closed");
1397+
}
1398+
break;
1399+
}
13971400
}
13981401
return Qtrue;
13991402
}

lib/oj/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
module Oj
22
# Current version of the module.
3-
VERSION = '3.16.3'
3+
VERSION = '3.16.4'
44
end

0 commit comments

Comments
 (0)