⚡ Sangsakala Proxy 🏠 Home
Skip to content

Improve error handling for cab extraction and limit module name to 128 characters - #28212

Closed
Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
masterfrom
cabhelp-gh
Closed

Aditya Patwardhan (adityapatwardhan) wants to merge 1 commit into
masterfrom
cabhelp-gh

Conversation

@adityapatwardhan

Copy link
Copy Markdown
Member

PR Summary

This pull request improves the robustness and security of the Cabinet extraction and Updatable Help code in PowerShell. The changes focus on better error handling for file operations, stricter validation of CAB entry paths, and defensive checks on module names to prevent issues with excessively long file paths.

Error handling and robustness improvements:

  • Added specific exception handling (e.g., UnauthorizedAccessException, ArgumentException, NotSupportedException, SecurityException) in FdiOpen to ensure that no exceptions escape into native code; instead, a failure is signaled with a return value, matching the existing IOException handling.
  • Improved FdiClose to handle invalid pointers and catch IOException, returning error codes instead of throwing exceptions.
  • In the FDI notification handler, now checks the result of FdiClose and aborts extraction if closing the file fails, preventing corrupt or truncated files from being reported as successfully extracted.
  • Corrected the check for valid file handles after CreateFile, ensuring that INVALID_HANDLE_VALUE is properly recognized as a failure.
  • Added explicit handling for the FdintNEXT_CABINET notification, returning an error code since only single-cabinet updates are supported.

Security and validation enhancements:

  • Strengthened path validation for CAB extraction: now rejects empty entry names and entries that resolve to the help directory root, preventing potential directory traversal or overwrite issues. [1] [2]

Defensive checks and user feedback:

  • Introduced a maximum module name length (MaxModuleNameLength = 128) to prevent excessively long module names from causing path or file name issues.
  • Added a user-facing error message and check in ProcessSingleModuleObject to reject modules with names exceeding the maximum length, with a localized error message in the resource file. [1] [2]

PR Context

PR Checklist

Copilot AI balanced review requested due to automatic review settings October 14, 2026 22:55
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Oct 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Regression coverage is needed for the module-name boundary and CAB extraction failure paths.

2 open findings
What changed in this PR

This PR hardens PowerShell’s Updatable Help processing against CAB extraction failures and oversized module names.

Changes:

  • Improves native callback error handling and file-handle validation.
  • Rejects empty/root CAB entry paths and multi-cabinet continuation.
  • Enforces a 128-character module-name limit with a resource-backed error message.
File Description
src/​System.Management.Automation/​resources/​HelpDisplayStrings.resx Adds the oversized module-name error message.
src/​System.Management.Automation/​help/​UpdatableHelpModuleInfo.cs Defines the module-name length limit.
src/​System.Management.Automation/​help/​UpdatableHelpCommandBase.cs Rejects oversized module names during help discovery.
src/​System.Management.Automation/​help/​CabinetNativeApi.cs Strengthens extraction validation and failure handling.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +486 to +488
if (closeResult != 0)
{
return IntPtr.Zero;
return;
}

if (module.Name.Length > UpdatableHelpModuleInfo.MaxModuleNameLength)
@iSazonov

Copy link
Copy Markdown
Collaborator

Dup #28203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants