Skip to content

Possible fix for #4485 #4487

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

Merged
merged 28 commits into from
Nov 19, 2024
Merged

Possible fix for #4485 #4487

merged 28 commits into from
Nov 19, 2024

Conversation

jordan-hoang
Copy link
Contributor

@jordan-hoang jordan-hoang commented Nov 6, 2024

Description

This fixes an issue with getting a crash when passing in a null string to json::parse(). It instead throws an exception.
Also added in a testcase to check for this.

Link to issue.
#4485


  • Changes are described in the pull request, or an existing issue is referenced.
  • The test suite compiles and runs without error.
  • Code coverage is 100%. Test cases can be added by editing the test suite.
  • The source code is amalgamated; that is, after making changes to the sources in the include/nlohmann directory, run make amalgamate to create the single-header files single_include/nlohmann/json.hpp and single_include/nlohmann/json_fwd.hpp. The whole process is described here.

Throw's an exception when i is nullptr,
also added a testcase for this scenario though most likely in the wrong test file.cpp
@jordan-hoang jordan-hoang requested a review from nlohmann November 9, 2024 08:50
@coveralls
Copy link

coveralls commented Nov 9, 2024

Coverage Status

coverage: 100.0%. remained the same
when pulling 97c4eac on jordan-hoang:fix-#4485
into 64f68dc on nlohmann:develop.

@github-actions github-actions bot added S and removed M labels Nov 9, 2024
Copy link

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @jordan-hoang
Please read and follow the Contribution Guidelines.

@nlohmann nlohmann linked an issue Nov 17, 2024 that may be closed by this pull request
2 tasks
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.

Please also consider the case that

nlohmann::json::parse(nullptr);

is called. This is then interpreted as FILE*, so please adjust inline file_input_adapter input_adapter(std::FILE* file) to also throw and exception if nullptr is provided.

@nlohmann
Copy link
Owner

(Also, please update to the latest develop branch to have a green CI)

@jordan-hoang
Copy link
Contributor Author

Gotcha, ahh so that's what it is, I noticed errors going away when I updated / merged from develop.
Thanks for letting me know.

@github-actions github-actions bot added M and removed S labels Nov 17, 2024
Copy link

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @jordan-hoang
Please read and follow the Contribution Guidelines.

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.

Please run "make amalgamate" using Astyle 3.1 (https://astyle.sourceforge.net) to fix the CI issues.

@nlohmann
Copy link
Owner

Note "make pretty" is not sufficient as it only indents the files in include and tests. You must run "make amalgamate" to create the single header files in single_includes.

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.

I added some comments to fix some errors in the CI.

Copy link

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @jordan-hoang
Please read and follow the Contribution Guidelines.

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.

One minor comment.

Copy link

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @jordan-hoang
Please read and follow the Contribution Guidelines.

@jordan-hoang
Copy link
Contributor Author

Sorry about all these tiny commits, I make the changes on a windows push em and then do the make amalgamate on a linux vm I have. Should really get make setup for windows so I don't have to do that.

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 added this to the Release 3.11.4 milestone Nov 19, 2024
Copy link

🔴 Amalgamation check failed! 🔴

The source code has not been amalgamated. @jordan-hoang
Please read and follow the Contribution Guidelines.

@nlohmann nlohmann merged commit 1f218e1 into nlohmann:develop Nov 19, 2024
128 checks passed
@nlohmann
Copy link
Owner

Thanks a lot!!!

@jordan-hoang jordan-hoang deleted the fix-#4485 branch November 20, 2024 23:26
@nlohmann nlohmann mentioned this pull request Dec 5, 2024
slowriot pushed a commit to slowriot/json that referenced this pull request Jan 10, 2025
* Possible fix for nlohmann#4485

Throw's an exception when i is nullptr,
also added a testcase for this scenario though most likely in the wrong test file.cpp

* quick cleanup

* Fix compile issues

* moved tests around, changed exceptions, removed a possibly unneeded include

* add back include <memory> for testing something

* Ninja doesn't like not having a \n, at end of file, adding it back

* update input_adapter file to deal with empty/null file ptr.

* ran make pretty

* added test for inputadapter

* ran make amalgamate

* Update tests/src/unit-deserialization.cpp

Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>

* Update tests/src/unit-deserialization.cpp

Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>

* Update input adapters.hpp with new includes

* fix unabigious use of _, (there was a double declare)

* did the amalagamate

* rm duplicate includes

* make amalgamate again

* reorder

* amalgamate

* moved it above

* amalgamate

---------

Co-authored-by: Jordan <jordan-hoang@users.noreply.github.com>
Co-authored-by: Niels Lohmann <niels.lohmann@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash when parsing nullptr
3 participants