From d337c63a1ba297015433e418c3378d7b3586a4f3 Mon Sep 17 00:00:00 2001 From: Robin David Date: Tue, 16 Jul 2024 17:08:23 +0200 Subject: [PATCH] fix Seed deserialization --- tritondse/seed.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tritondse/seed.py b/tritondse/seed.py index 9925ade..ac76b42 100644 --- a/tritondse/seed.py +++ b/tritondse/seed.py @@ -234,17 +234,20 @@ def from_bytes(raw_seed: bytes, status: SeedStatus = SeedStatus.NEW) -> 'Seed': :rtype: Seed """ try: - data = json.loads(raw_seed) - - if not isinstance(data, dict): # it might happen that files contains only digit which is a valid JSON - return Seed(raw_seed, status) - - if 'files' in data and 'argv' in data: - return Seed(CompositeData.from_dict(data), status) - else: # Else still consider file as raw bytes + if raw_seed.startswith(b"{"): + data = json.loads(raw_seed) + + # Check that it contains the expected keys + if 'files' in data and 'argv' in data: + return Seed(CompositeData.from_dict(data), status) + else: # Else still consider file as raw bytes + return Seed(raw_seed, status) + else: return Seed(raw_seed, status) except (json.JSONDecodeError, UnicodeDecodeError): return Seed(raw_seed, status) + except ValueError: # JSON parser might raise value error + return Seed(raw_seed, status) @staticmethod def from_file(path: PathLike, status: SeedStatus = SeedStatus.NEW) -> 'Seed':