Skip to content
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

[BUG] Unhandled Exception Using argv #4123

Open
MrCuriousGuy opened this issue Mar 8, 2025 · 1 comment
Open

[BUG] Unhandled Exception Using argv #4123

MrCuriousGuy opened this issue Mar 8, 2025 · 1 comment
Labels
bug Something isn't working mojo Issues that are related to mojo

Comments

@MrCuriousGuy
Copy link

MrCuriousGuy commented Mar 8, 2025

Bug description

Actual behavior

argv is imported from sys and used. If an arg is accessed that is outside the range of provided arguments, the program crashes without a handled exception

Expected behavior

When an argument outside the range of provided argv is accessed, either an exception is raised or some kind of empty value is returned.

Steps to reproduce

Run the following program from the CLI. Call the script without arguments. It should crash. If you provide an argument, it should not crash.

from sys import argv

def main():
    var arguments = argv()

    print(len(arguments))
    print(arguments[0])
    print(arguments[1])

System information

  • Provide the system information by running magic info.
    Magic version: 0.7.0
    System

   Pixi version: 0.41.3
       Platform: linux-64

Virtual packages: __unix=0=0
: __linux=5.15.146.1=0
: __glibc=2.35=0
: __archspec=1=skylake
Cache dir: /home/mojo/.cache/rattler/cache
Auth storage: /home/mojo/.rattler/credentials.json
Config locations: No config files found

Global

        Bin dir: /home/mojo/.modular/bin
Environment dir: /home/mojo/.modular/envs
   Manifest dir: /home/mojo/.modular/manifests/pixi-global.toml

Project

           Name: app
        Version: 0.1.0
  Manifest file: /app/mojoproject.toml
   Last updated: 28-02-2025 20:59:04

Environments

    Environment: default
       Features: default
       Channels: https://conda.modular.com/max-nightly, https://conda.modular.com/max, https://repo.prefix.dev/modular-community, conda-forge

Dependency count: 1
Dependencies: max
Target platforms: linux-64

  • Provide version information for MAX (includes Mojo) by pasting the output of magic list max.
    Package Version Build Size Kind Source
    max 25.2.0.dev2025022805 release 9.7 KiB conda max
    max-core 25.2.0.dev2025022805 release 238.3 MiB conda max-core
    max-python 25.2.0.dev2025022805 release 117.9 MiB conda max-python
@MrCuriousGuy MrCuriousGuy added bug Something isn't working mojo Issues that are related to mojo labels Mar 8, 2025
@soraros
Copy link
Contributor

soraros commented Mar 8, 2025

I think this is only temporary, and we probably can't do better until much later. argv returns a VariadicList, and an out-of-bounds index is unfortunately UB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo Issues that are related to mojo
Projects
None yet
Development

No branches or pull requests

2 participants