Skip to content

fix: error in FindPropertyIndex for non-string dependencies elements#2377

Open
KowalskiThomas wants to merge 1 commit into
Tencent:masterfrom
KowalskiThomas:kowalski/fix-error-in-findpropertyindex-for-non-string-dependencies-elements
Open

fix: error in FindPropertyIndex for non-string dependencies elements#2377
KowalskiThomas wants to merge 1 commit into
Tencent:masterfrom
KowalskiThomas:kowalski/fix-error-in-findpropertyindex-for-non-string-dependencies-elements

Conversation

@KowalskiThomas
Copy link
Copy Markdown

@KowalskiThomas KowalskiThomas commented Apr 27, 2026

What is this PR?

This PR fixes a crash that I encountered.

Schema::Schema processes dependencies arrays by calling FindPropertyIndex on each element to look up property names. FindPropertyIndex calls GetStringLength, which asserts IsString, but the spec does not forbid non-string elements in a dependencies array, so a schema like {"dependencies":{"a":[0,2]}} caused an assertion failure (SIGABRT).

This PR fixes it by checking targetItr->IsString() and adds a regression test.

...
#8 0x7f1dde652e95 in __assert_fail (/lib/x86_64-linux-gnu/libc.so.6+0x39e95) (BuildId: 095c7ba148aeca81668091f718047078d57efddb)
#9 0x55c7ae2e0360 in rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::GetStringLength() const /home/user/rapidjson/include/rapidjson/document.h:1858:40
#10 0x55c7ae2df16a in rapidjson::internal::Schema<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> >::FindPropertyIndex(rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, unsigned int*) const /home/user/rapidjson/include/rapidjson/schema.h:1518:29
#11 0x55c7ae2d1a1b in rapidjson::internal::Schema<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> >::Schema(rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>*, rapidjson::GenericPointer<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> const&, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, rapidjson::CrtAllocator*, rapidjson::GenericUri<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> const&) /home/user/rapidjson/include/rapidjson/schema.h:740:33
#12 0x55c7ae2d6996 in rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>::CreateSchema(rapidjson::internal::Schema<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> > const**, rapidjson::GenericPointer<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> const&, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, rapidjson::GenericUri<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> const&) /home/user/rapidjson/include/rapidjson/schema.h:2197:78
#13 0x55c7ae2d6103 in rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>::CreateSchemaRecursive(rapidjson::internal::Schema<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> > const**, rapidjson::GenericPointer<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> const&, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, rapidjson::GenericUri<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> const&) /home/user/rapidjson/include/rapidjson/schema.h:2173:37
#14 0x55c7ae2c00a2 in rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator>::GenericSchemaDocument(rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> > const&, char const*, unsigned int, rapidjson::IGenericRemoteSchemaDocumentProvider<rapidjson::GenericSchemaDocument<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> >*, rapidjson::CrtAllocator*, rapidjson::GenericPointer<rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >, rapidjson::CrtAllocator> const&, rapidjson::Specification const&) /home/user/rapidjson/include/rapidjson/schema.h:1886:13
...

Schema::Schema processes dependencies arrays by calling `FindPropertyIndex`
on each element to look up property names. `FindPropertyIndex` calls
`GetStringLength` which asserts `IsString`, but the spec does not forbid
non-string elements in a dependencies array, so a schema like
`{"dependencies":{"a":[0,2]}}` caused an assertion failure (SIGABRT).
@tencent-adm
Copy link
Copy Markdown
Member

tencent-adm commented Apr 27, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants