Enhance metadata processing security, stability, and documentation#95
Open
glebtarasov-creator wants to merge 5 commits into
Open
Enhance metadata processing security, stability, and documentation#95glebtarasov-creator wants to merge 5 commits into
glebtarasov-creator wants to merge 5 commits into
Conversation
- Replace defusedxml.lxml with defusedxml.ElementTree for safer XML parsing - Improve resource management in extract_metadata function with proper file handle closing - Add retry mechanism for temporary directory cleanup on Windows - Enhance PNG metadata clearing by using img.copy() to preserve image properties - Add assertions and proper cleanup in test functions - Improve code readability and formatting
…tion - Update return type documentation to accurately reflect actual return values - Return the file path even when metadata is already cleared to maintain consistency - This ensures the function behavior matches its documented contract
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 12 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
- Remove unused imports: 'art' and 'errors' modules are no longer used - Remove unused functions: 'extract_metadata', 'dmeta_help', and 'run_dmeta' are deleted - Improve return value documentation in clear function - Add missing returns for unsupported formats in clear and update functions - Format code to improve readability, especially in exception handling
- Refactor clear and update functions to use a shared _process_metadata function - Add extract_metadata function to retrieve metadata from Microsoft files - Implement _cleanup_extracted function to handle cleanup after processing - Update clear_all and update_all functions to use new _process_metadata - Improve error handling and verbose output in various functions
- Add _output_path function to determine the output file path - Implement _extract_and_prepare for consistent file extraction - Create _repack_and_cleanup function to handle file repacking - Simplify _process_metadata by using new helper functions - Improve code readability and reduce duplication
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.
Summary of Changes
This PR enhances the security and stability of the metadata processing functionality in DMeta.
Changes Implemented
Security Enhancement:
defusedxml.lxmlwithdefusedxml.ElementTreefor safer XML parsingResource Management Improvements:
extract_metadatafunction with proper file handle closingimg.copy()to preserve image properties while removing metadataAPI Consistency Fixes:
clear()function to match its documentationTest Suite Improvements:
Code Quality:
Motivation
These changes address Windows-specific file handling issues and improve the overall security posture of the library by using safer XML parsing methods. The enhanced resource management prevents potential PermissionError exceptions during temporary directory cleanup on Windows systems. Additionally, fixing the return value consistency ensures the API behaves predictably according to its documentation.
Backward Compatibility
All changes maintain full backward compatibility with existing functionality. The API remains the same, but now behaves consistently with its documented contract.