Skip to content

Fix/exec empty arguments crash - #1783

Merged
jglogan merged 2 commits into
apple:mainfrom
SEPURI-SAI-KRISHNA:fix/exec-empty-arguments-crash
Jun 25, 2026
Merged

Fix/exec empty arguments crash#1783
jglogan merged 2 commits into
apple:mainfrom
SEPURI-SAI-KRISHNA:fix/exec-empty-arguments-crash

Conversation

@SEPURI-SAI-KRISHNA

@SEPURI-SAI-KRISHNA SEPURI-SAI-KRISHNA commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

swift-argument-parser enforces that arguments is non-empty before
run() is invoked, so the force-unwrap of arguments.first! is not
reachable in practice.

However, the guard makes the invariant explicit in the code itself,
removes reliance on ArgumentParser's implicit enforcement, and would
satisfy force-unwrap lint rules if enabled in the future

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@jglogan

jglogan commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@SEPURI-SAI-KRISHNA I don't see it crash at runtime.

% container ls
Warning! Running debug build. Performance may be degraded.
ID                 IMAGE                                         OS     ARCH   STATE    IP               CPUS  MEMORY   STARTED
6f6ca580-registry  docker-upstream.apple.com/library/registry:3  linux  arm64  running  192.168.64.3/24  4     1024 MB  2026-06-23T02:38:21Z

% container exec 6f6ca580-registry
Warning! Running debug build. Performance may be degraded.
Error: Missing expected argument '<arguments> ...'
Help:  <arguments>  New process arguments
Usage: container exec [<options>] <container-id> <arguments> ...
  See 'container exec --help' for more information.

That's because swift-argument-parser enforces the invariant arguments.count > 0 before run() is even invoked.

The fix you provide is good defensive programming though, and if we were to turn on lint checks at some point we would need to create exceptions for the few force-try expressions scattered through the code.

@github-actions github-actions Bot added the cli label Jun 23, 2026
@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Contributor Author

@jglogan Thanks for the context. You're right that ArgumentParser enforces this before run() is invoked I missed that invariant. Happy to close this if the team prefers keeping the codebase as is. Alternatively, since you mentioned lint checks would flag force-unwraps eventually, I can keep it as a preemptive cleanup but I'll defer to your preference.

@SEPURI-SAI-KRISHNA
SEPURI-SAI-KRISHNA force-pushed the fix/exec-empty-arguments-crash branch from 7a23825 to ac109e9 Compare June 23, 2026 04:25
@jglogan

jglogan commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

@SEPURI-SAI-KRISHNA I think the change is fine - you just need to configure commit signing, and perhaps update your Motivation and Context description.

@SEPURI-SAI-KRISHNA
SEPURI-SAI-KRISHNA force-pushed the fix/exec-empty-arguments-crash branch from ac109e9 to a615d71 Compare June 23, 2026 14:46
@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Contributor Author

@jglogan I have added signature. please check. I have also updated the Motivation and Context.

@JaewonHur
JaewonHur force-pushed the fix/exec-empty-arguments-crash branch from a615d71 to 870199c Compare June 25, 2026 15:48
@JaewonHur

Copy link
Copy Markdown
Contributor

@SEPURI-SAI-KRISHNA Oops sorry! The signatures have gone while I rebase them on latest main. Could you force push the signed commit again..?

@jglogan

jglogan commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@SEPURI-SAI-KRISHNA Could you rebase this commit to the latest main and force-push the changes? We tried the rebase from the GitHub UI but that dropped the commit signatures.

The PR needs to be rebased to pick up an integration test workaround unrelated to your change. Thank you!

@SEPURI-SAI-KRISHNA
SEPURI-SAI-KRISHNA force-pushed the fix/exec-empty-arguments-crash branch from 870199c to 7c2e78d Compare June 25, 2026 17:13
@SEPURI-SAI-KRISHNA

Copy link
Copy Markdown
Contributor Author

@jglogan @JaewonHur I have rebase and force-pushed.

@github-actions

Copy link
Copy Markdown

Code Coverage

Tier Line Coverage
Unit 33.34%
Integration 23.02%
Combined 55.51%

@jglogan
jglogan merged commit 137b3bd into apple:main Jun 25, 2026
3 checks passed
@jglogan

jglogan commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@SEPURI-SAI-KRISHNA Merged, thanks again for your contribution!

saehejkang pushed a commit to saehejkang/container that referenced this pull request Jul 16, 2026
- `swift-argument-parser` enforces that `arguments` is
  non-empty before `run()` is invoked, so the force-unwrap
  of `arguments.first!` is not reachable in practice. However,
  the guard makes the invariant explicit in the code itself,
  removes reliance on ArgumentParser's implicit
  enforcement, and would satisfy force-unwrap lint rules
  if enabled in the future.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants