Skip to content

Commit

Permalink
Merge pull request #178 from brianmario/brianmario/prevent-bad-read
Browse files Browse the repository at this point in the history
Fix potential bad read
  • Loading branch information
brianmario committed Nov 7, 2017
2 parents b634855 + a8ca8f4 commit fe083cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ext/yajl/yajl_encode.c
Expand Up @@ -162,8 +162,8 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
end+=3;
/* check if this is a surrogate */
if ((codepoint & 0xFC00) == 0xD800) {
end++;
if (str[end] == '\\' && str[end + 1] == 'u') {
if (end + 2 < len && str[end + 1] == '\\' && str[end + 2] == 'u') {
end++;
unsigned int surrogate = 0;
hexToDigit(&surrogate, str + end + 2);
codepoint =
Expand Down
7 changes: 7 additions & 0 deletions spec/parsing/one_off_spec.rb
Expand Up @@ -2,6 +2,13 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')

describe "One-off JSON examples" do
it "should not blow up with a bad surrogate trailer" do
# https://github.com/brianmario/yajl-ruby/issues/176
bad_json = "{\"e\":{\"\\uD800\\\\DC00\":\"a\"}}"

Yajl::Parser.new.parse(bad_json)
end

it "should parse 23456789012E666 and return Infinity" do
infinity = (1.0/0)
silence_warnings do
Expand Down

0 comments on commit fe083cc

Please sign in to comment.