json.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "WallpaperEngine/Assets/AssetLocator.h"
  2. #include "WallpaperEngine/Data/JSON.h"
  3. #include "WallpaperEngine/Data/Model/Project.h"
  4. #include "WallpaperEngine/Data/Model/Wallpaper.h"
  5. #include "WallpaperEngine/Data/Parsers/MaterialParser.h"
  6. #include "WallpaperEngine/Data/Parsers/ObjectParser.h"
  7. #include "WallpaperEngine/Data/Parsers/ProjectParser.h"
  8. #include "WallpaperEngine/Data/Parsers/WallpaperParser.h"
  9. #include "WallpaperEngine/FileSystem/Container.h"
  10. #include <tuple>
  11. using namespace WallpaperEngine;
  12. using Data::JSON::JSON;
  13. namespace {
  14. Assets::AssetLocatorUniquePtr emptyAssets () {
  15. return std::make_unique<Assets::AssetLocator> (std::make_unique<FileSystem::Container> ());
  16. }
  17. }
  18. // the input is read as every kind of JSON file the loader knows: project, scene, object, material
  19. extern "C" int LLVMFuzzerTestOneInput (const uint8_t* data, size_t size) {
  20. JSON json;
  21. try {
  22. json = JSON::parseAsset (std::string (reinterpret_cast<const char*> (data), size));
  23. } catch (const std::exception&) {
  24. return 0;
  25. }
  26. Data::Model::Project project {};
  27. project.assetLocator = emptyAssets ();
  28. try {
  29. std::ignore = Data::Parsers::ProjectParser::parse (json, emptyAssets ());
  30. } catch (const std::exception&) { }
  31. try {
  32. std::ignore = Data::Parsers::ObjectParser::parse (json, project);
  33. } catch (const std::exception&) { }
  34. try {
  35. std::ignore = Data::Parsers::WallpaperParser::parse (json, project);
  36. } catch (const std::exception&) { }
  37. try {
  38. std::ignore = Data::Parsers::MaterialParser::parse (json, "fuzz.json", project);
  39. } catch (const std::exception&) { }
  40. return 0;
  41. }