From 706466f63b0595e46db73e192310662e63e96c24 Mon Sep 17 00:00:00 2001 From: KnugiHK <24708955+KnugiHK@users.noreply.github.com> Date: Sun, 1 Jun 2025 11:54:24 +0800 Subject: [PATCH] Enforce a tighter check on the input of size_str --- Whatsapp_Chat_Exporter/utility.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Whatsapp_Chat_Exporter/utility.py b/Whatsapp_Chat_Exporter/utility.py index 268247a..c32e536 100644 --- a/Whatsapp_Chat_Exporter/utility.py +++ b/Whatsapp_Chat_Exporter/utility.py @@ -118,6 +118,9 @@ def readable_to_bytes(size_str: str) -> int: 'YB': 1024**8 } size_str = size_str.upper().strip() + match = re.fullmatch(r'^(\d+(\.\d+)?)\s*([KMGTPEZY]?B)?$', size_str) + if not match: + raise ValueError("Invalid size format. Expected format like '10MB', '1024GB', or '512'.") unit = ''.join(filter(str.isalpha, size_str)).strip() number = ''.join(c for c in size_str if c.isdigit() or c == '.').strip() if unit not in SIZE_UNITS: