Skip to content

Fix ArgumentOutOfRangeException in DownloadFromResultsContainer when link has no query - #17704

Merged
mmitche merged 2 commits into
dotnet:mainfrom
austinaviv:fix-results-download-uri-parsing
Oct 26, 2026
Merged

mmitche merged 2 commits into
dotnet:mainfrom
austinaviv:fix-results-download-uri-parsing

Conversation

@austinaviv

Copy link
Copy Markdown
Contributor

Fixes #17703

Description

When DownloadFromResultsContainer downloads work item results using a read SAS token from resultsUri.ResultsUriRSAS, it was unconditionally calling fileAvailableForDownload.Link.Substring(0, fileAvailableForDownload.Link.LastIndexOf('?')). If the file link is a bare blob URI without query parameters, LastIndexOf('?') returns -1 and causes Substring(0, -1) to throw an unhandled ArgumentOutOfRangeException.

Changes

  • Extract URI and SAS parsing into GetBlobUriAndSas.
  • Safely check if the link contains ? using IndexOf('?') before substringing. If no query string is present, keep the URI intact.
  • Trim any leading ? from the results SAS token before passing to AzureSasCredential, consistent with other Helix tasks.
  • Guard MetadataToWrite and WorkItems in ExecuteCore against null.
  • Add unit tests in DownloadFromResultsContainerTests covering all query/SAS combinations.

@austinaviv

Copy link
Copy Markdown
Contributor Author

/azp run arcade-pr

@azure-pipelines

Copy link
Copy Markdown
Commenter does not have sufficient privileges for PR 17704 in repo dotnet/arcade

@mmitche

mmitche commented Oct 15, 2026

Copy link
Copy Markdown
Member

@austinaviv Can you check and see whether this needs resolution in the job monitor too?

@austinaviv

Copy link
Copy Markdown
Contributor Author

@austinaviv Can you check and see whether this needs resolution in the job monitor too?

Sure, I'll check the Job Monitor code for the same URI parsing issue and verify whether it can encounter blob URLs without query parameters. If the same issue exists, I'll add the corresponding fix and tests.

Thanks for your review

@austinaviv

austinaviv commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

I investigated Job Monitor. In AzureBlobClientFactory, line 20 already had a blobUri.Contains('?') check so bare URLs without query strings did not throw an exception there.

However, it was using LastIndexOf('?') rather than IndexOf('?') and did not trim leading ? characters from SAS tokens before passing them to AzureSasCredential.

I pushed an update aligning AzureBlobClientFactory with the same safe URI and SAS token parsing logic, along with unit test coverage in AzureBlobClientFactoryTests.

@austinaviv

Copy link
Copy Markdown
Contributor Author

Hi @mmitche, just checking in on this when you have a moment. All CI checks are passing, and the Job Monitor adjustments along with unit tests are in place. Please let me know if there is anything else needed.

@mmitche
mmitche merged commit ea98218 into dotnet:main Oct 26, 2026
17 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 27, 2026
@premun

premun commented Nov 23, 2026

Copy link
Copy Markdown
Member

/backport to release/10.0

@premun

premun commented Nov 23, 2026

Copy link
Copy Markdown
Member

/backport to release/11.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@premun backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick ea982189bb40e0f9bae13e31f3fd1db4c5c8283c

Auto-merging src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
CONFLICT (content): Merge conflict in src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
error: could not apply ea982189b... Fix ArgumentOutOfRangeException in DownloadFromResultsContainer when link has no query (#17704)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix URI query stripping in DownloadFromResultsContainer
.git/rebase-apply/patch:127: trailing whitespace.
                    if (string.IsNullOrEmpty(sasToken)) 
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M	src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
CONFLICT (content): Merge conflict in src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix URI query stripping in DownloadFromResultsContainer
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@github-actions

Copy link
Copy Markdown
Contributor

@premun backporting to release/11.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick ea982189bb40e0f9bae13e31f3fd1db4c5c8283c

Auto-merging src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
CONFLICT (content): Merge conflict in src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
error: could not apply ea982189b... Fix ArgumentOutOfRangeException in DownloadFromResultsContainer when link has no query (#17704)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fix URI query stripping in DownloadFromResultsContainer
.git/rebase-apply/patch:127: trailing whitespace.
                    if (string.IsNullOrEmpty(sasToken)) 
warning: 1 line adds whitespace errors.
Using index info to reconstruct a base tree...
M	src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
CONFLICT (content): Merge conflict in src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fix URI query stripping in DownloadFromResultsContainer
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DownloadFromResultsContainer crashes with ArgumentOutOfRangeException when file link has no query parameters

3 participants