fixes a crash when skipping array fields during decoding#1813
Conversation
|
@t089 is there a reproducer test case you could add to the suite with this fix? |
|
Sure, before I check myself, does the Suite Support "exit tests" to observe a crash? |
|
Looks like it's supported on a number of platforms. We'd have to crib a conditional compiler setting from Foundation's But we're not testing an expected assertion here right? Just a crash fix? The test running to completion should be verification enough. Using the process exit infrastructure might even make it harder for us to get backtrace diagnostics if it were to start crashing again later. |
|
Ok got it. Yes then I can add a test case for this. |
|
Thanks a ton! You probably want to rebase the branch on top of the latest version that has the various test fixes. |
d5a13ab to
2b038cd
Compare
2b038cd to
4dc4aea
Compare
|
@kperryua added a couple of tests |
876cae4
into
swiftlang:experimental/new-codable
Fixes a crash in
skipValue()when skipping array/dictionary values during decoding.Motivation:
When implementing
JSONDecodableconformance withdecodeEachKeyAndValueand adefault: breakto skip unknown keys, decoding crashes withpreconditionFailure("Wrong node type")if any of the unknown fields values is an array (or a nested object containing arrays). This is becauseskipValue()delegates toBlackHoleVisitorviaArrayDecoder/StructDecoder, but these decoders inherit the parent's coding path node (e.g..dictionary) instead of pushing their own. WhendecodeEachElementcallsincrementArrayIndex()on the inherited.dictionarynode, it hits the precondition failure.Modifications:
ParserState.skipValue(), push the appropriateCodingPathNodebefore creating the sub-decoder for both._openbraceand._openbracketcases.currentTopCodingPathNodeat the new node before constructing theStructDecoder/ArrayDecoderwithExtendedLifetimeto ensure the node stays alive).Result:
Skipping keys in JSON whose values are objects or array no longer crashes.
Testing:
Validated with a reproducer that no longer crashes after the patch is applied.