Skip to content

Replace all pickle load with safe load #2252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 23, 2025
Merged

Replace all pickle load with safe load #2252

merged 4 commits into from
Jul 23, 2025

Conversation

yiliu30
Copy link
Contributor

@yiliu30 yiliu30 commented Jul 22, 2025

Type of Change

feature or bug fix or documentation or validation or others
API changed or not

Description

detail description

Expected Behavior & Potential Risk

the expected behavior that triggered by this PR

How has this PR been tested?

how to reproduce the test (including hardware information)

Dependency Change?

any library dependency introduced or removed

Signed-off-by: yiliu30 <yi4.liu@intel.com>
@yiliu30 yiliu30 requested a review from Copilot July 22, 2025 05:07
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enhances security by replacing unsafe pickle.load() calls with a safe loading mechanism to prevent potential code execution vulnerabilities. The changes introduce a centralized safe pickle loading approach and extend the allowed classes for unpickling.

  • Extracts and enhances the SafeUnpickler class to module level for reusability
  • Creates a centralized _safe_pickle_load() function to replace all direct pickle.load() calls
  • Expands allowed classes to include additional ML frameworks beyond just numpy
Comments suppressed due to low confidence (1)

neural_compressor/utils/utility.py:136

  • The variable name "allowed_classes" is misleading as it contains module prefixes, not class names. Consider renaming to "allowed_module_prefixes" or "allowed_modules" for clarity.
        allowed_classes = ["nummpy", "torch", "tensorflow", "onnx", "onnxruntime"]

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@chensuyue chensuyue added this to the 3.5 milestone Jul 22, 2025
yiliu30 added 2 commits July 22, 2025 04:38
Signed-off-by: yiliu30 <yi4.liu@intel.com>
@chensuyue chensuyue merged commit a3da6e8 into master Jul 23, 2025
33 checks passed
@chensuyue chensuyue deleted the fix-pickle-2nd branch July 23, 2025 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants