From 517dd4dbb8babb5b69e3ed6eabdaedeb177bd977 Mon Sep 17 00:00:00 2001 From: Milo Yip Date: Mon, 17 Oct 2016 14:25:24 +0800 Subject: [PATCH] Fix failing to resolve $ref in allOf causes crash in SchemaValidator::StartObject() --- include/rapidjson/schema.h | 3 +++ test/unittest/schematest.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/include/rapidjson/schema.h b/include/rapidjson/schema.h index 288b93d..420db62 100644 --- a/include/rapidjson/schema.h +++ b/include/rapidjson/schema.h @@ -1366,6 +1366,9 @@ public: new (schemaMap_.template Push()) SchemaEntry(refEntry->source, const_cast(s), false, allocator_); } } + else if (refEntry->schema) + *refEntry->schema = SchemaType::GetTypeless(); + refEntry->~SchemaRefEntry(); } diff --git a/test/unittest/schematest.cpp b/test/unittest/schematest.cpp index 6a8b685..4780516 100644 --- a/test/unittest/schematest.cpp +++ b/test/unittest/schematest.cpp @@ -1308,6 +1308,14 @@ TEST(SchemaValidator, Issue608) { INVALIDATE(s, "{\"a\" : null, \"a\" : null}", "", "required", ""); } +// Fail to resolve $ref in allOf causes crash in SchemaValidator::StartObject() +TEST(SchemaValidator, Issue728_AllOfRef) { + Document sd; + sd.Parse("{\"allOf\": [{\"$ref\": \"#/abc\"}]}"); + SchemaDocument s(sd); + VALIDATE(s, "{\"key1\": \"abc\", \"key2\": \"def\"}", true); +} + #ifdef __clang__ RAPIDJSON_DIAG_POP #endif