From ec0aeba86160bf0ea5447f0a565f24ccb080451b Mon Sep 17 00:00:00 2001 From: hert1zm <44004413+hert1zm@users.noreply.github.com> Date: Wed, 18 Feb 2026 12:30:22 +0100 Subject: [PATCH 1/2] Improve image reading with buffer validation Add buffer check for image reading to handle empty or corrupted files. --- libs/autoDialog.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libs/autoDialog.py b/libs/autoDialog.py index 6e605b1..0cb8a44 100644 --- a/libs/autoDialog.py +++ b/libs/autoDialog.py @@ -41,15 +41,22 @@ def run(self): if self.handle == 0: self.listValue.emit(img_path) if self.model == "paddle": - img = cv2.imdecode( - np.fromfile(img_path, dtype=np.uint8), cv2.IMREAD_COLOR - ) + buf = np.fromfile(img_path, dtype=np.uint8) + if buf.size == 0: + logger.warning( + "Failed to read the image's buffer. The file may be corrupted or in an unsupported format : %s", + img_path, + ) + self.result_dic = None + continue + img = cv2.imdecode(buf, cv2.IMREAD_COLOR) if img is None: logger.warning( "Failed to decode image file %s. The file may be corrupted or in an unsupported format.", img_path, ) self.result_dic = None + continue else: h, w, _ = img.shape if h > 32 and w > 32: From 35927b87e85c5368f7fd25098447d296766a5f68 Mon Sep 17 00:00:00 2001 From: Wang Xin Date: Mon, 23 Mar 2026 21:40:15 +0800 Subject: [PATCH 2/2] Apply suggestion from @Copilot Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- libs/autoDialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/autoDialog.py b/libs/autoDialog.py index 0cb8a44..e1ba4aa 100644 --- a/libs/autoDialog.py +++ b/libs/autoDialog.py @@ -44,7 +44,7 @@ def run(self): buf = np.fromfile(img_path, dtype=np.uint8) if buf.size == 0: logger.warning( - "Failed to read the image's buffer. The file may be corrupted or in an unsupported format : %s", + "Failed to read the image's buffer. The file may be corrupted or in an unsupported format: %s", img_path, ) self.result_dic = None