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 potential bad read #178

Merged
merged 1 commit into from Nov 7, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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