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

prevent ndarray dimension vector from recusive array, nlohmann/json#3500 #3502

Merged
merged 1 commit into from
May 20, 2022

Conversation

fangq
Copy link
Contributor

@fangq fangq commented May 18, 2022

I believe the issue @nlohmann found in #3500 (comment) is because the ndarray dimension vector parsing is too relax - permitting embedded arrays (which can result in unpredictable results).

I am adding an exception here to avoid such case. let me know if you still see errors.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling cd7a58d on NeuroJSON:issue3500 into 93c9e0c on nlohmann:develop.

@nlohmann
Copy link
Owner

nlohmann commented May 19, 2022

This fix does not address the issue I described: you seem to open an object with fixed size of 3 which is never closed, yielding a problem in the SAX parser. I fuzzed this branch (together with the assertions from #3498) and got the following failing input: crash2.bjdata.zip

This generates the following SAX events:

<array>
    <array>
        <object>
            <key key="��" />
            <array>
                <number_integer val="27739" />
                <boolean val="true" />
                <object size="3">                   <!-- open an object with size 3 -->
                    <key key="_ArraySize_" />
                    <array size="2">
                        <number_integer val="6689" />
                        <number_integer val="0" />
                    </array>                        <!-- the first object entry -->
                    <array size="0">                <!-- ERROR: a value without key -->
                    </array>
                    <boolean val="true" />          <!-- ERROR: a value without key -->
                    <boolean val="true" />          <!-- ERROR: a value without key -->
                    <boolean val="true" />          <!-- ERROR: a value without key -->
                    <boolean val="true" />          <!-- ERROR: a value without key -->
                </array>                            <!-- ERROR: closing array (not object) -->
                <key key="" />
                <number_unsigned val="30069" />
                <parse_error id="71" token="<end of file>" />

Again, for line

if (JSON_HEDLEY_UNLIKELY(!sax->start_object(3) || !sax->key(key) || !sax->start_array(dim.size())))

please check

  • Why is the size 3 hard-coded?
  • Where to add the required sax->end_object() call?

@nlohmann
Copy link
Owner

I moved the open issue to #3503. This PR fixes another bug in the BJData reader, so it should be merged.

@nlohmann nlohmann added this to the Release 3.11.0 milestone May 20, 2022
@nlohmann nlohmann self-assigned this May 20, 2022
Copy link
Owner

@nlohmann nlohmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@nlohmann nlohmann merged commit 41226d0 into nlohmann:develop May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants