Improve image reading with buffer validation#240
Open
hert1zm wants to merge 1 commit intoPFCCLab:mainfrom
Open
Improve image reading with buffer validation#240hert1zm wants to merge 1 commit intoPFCCLab:mainfrom
hert1zm wants to merge 1 commit intoPFCCLab:mainfrom
Conversation
Add buffer check for image reading to handle empty or corrupted files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, if the image set contains even a single corrupted or unreadable file, the entire application crashes during auto-detection/auto-recognition. This patch introduces a validation step on the image buffer before calling
cv2.imdecode(). If the buffer is empty or invalid, the application logs a warning and skips the file instead of raising an exception. This prevents the full process from terminating unexpectedly and avoids losing progress when processing large batches of images.Since this problem could occur in multiple occasions, consider building a custom utility to replace all the calls to
cv2.imdecode()to implement a buffer validation and prevent crashing in case the image set contains corrupted or unusable images: