azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Fix out-of-bounds safety in BlobToFileNameResolver

Open Ronitsabhaya75 opened this issue 6 months ago • 6 comments

Description

This pull request resolves two safety-critical TODO items in the filename conflict resolution logic of the Azure Storage module (BlobToFileNameResolver.cs):

  1. MaxFileNameLength Guard Clause: Added validation to check if maxFileNameLength is non-positive (<= 0). If so, the code now throws a clear ArgumentOutOfRangeException instead of proceeding with invalid dimensions.
  2. Bounds Protection during Truncation: Implemented defensive boundaries when calculating trimLength. If the required trimming size exceeds the actual length of the filename base (which previously caused out-of-bounds Remove() index exceptions), the start index is now safely clamped to 0 to clear the base filename and return the postfix and extension safely.

No changes were made to cmdlet interfaces or public API signatures.

Mandatory Checklist

  • Please choose the target release of Azure PowerShell. (⚠️Target release is a different concept from API readiness. Please click below links for details.)

    • [x] General release
    • [ ] Public preview
    • [ ] Private preview
    • [ ] Engineering build
    • [ ] No need for a release
  • [x] Check this box to confirm: I have read the Submitting Changes section of CONTRIBUTING.md and reviewed the following information:

  • SHOULD update ChangeLog.md file(s) appropriately
    • Update src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md.
      • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header in the past tense.
    • Should not change ChangeLog.md if no new release is required, such as fixing test case only.
  • SHOULD regenerate markdown help files if there is cmdlet API change. Instruction
  • SHOULD have proper test coverage for changes in pull request.
  • SHOULD NOT adjust version of module manually in pull request

@renish-patel thank you for testing and giving me help to write

Ronitsabhaya75 avatar May 22 '26 14:05 Ronitsabhaya75

Thanks for your contribution! The pull request validation has started. Please revisit this comment for updated status.

Thank you for your contribution @Ronitsabhaya75! We will review the pull request and get back to you soon.

Commenter does not have sufficient privileges for PR 29672 in repo Azure/azure-powershell

azure-pipelines[bot] avatar May 22 '26 15:05 azure-pipelines[bot]

/azp run

thomas-temby avatar May 28 '26 02:05 thomas-temby

Azure Pipelines successfully started running 3 pipeline(s).

azure-pipelines[bot] avatar May 28 '26 02:05 azure-pipelines[bot]

@thomas-temby can you please review this.

Ronitsabhaya75 avatar May 29 '26 15:05 Ronitsabhaya75