Repository: nushell/nushell
File: crates/nu-command/src/filters/drop/nth.rs (Rust)

Code before:
            } else if let Ok(range) = value.as_range() {
                match range {
                    Range::IntRange(range) => {
                        let start = range.start();
                        if start < 0 {
                            return Err(ShellError::UnsupportedInput {
                                msg: "drop nth accepts only positive ints".into(),
                                input: "value originates from here".into(),
                                msg_span: head,
                                input_span: value.span(),
                            });
                        }

                        let end = match range.end() {
                            Bound::Included(end) => end,
                            Bound::Excluded(end) => end - 1,
                            Bound::Unbounded => {
                                let start = range.start() as usize;
                                return Ok(input
                                    .into_iter()
                                    .take(start)
                                    .into_pipeline_data_with_metadata(
                                        head,
                                        engine_state.signals().clone(),
                                        metadata,
                                    ));
                            }
                        };

                        if end < start {
                            return Err(ShellError::UnsupportedInput {
                                msg:
                                    "The upper bound needs to be equal or larger to the lower bound"
                                        .into(),
                                input: "value originates from here".into(),
                                msg_span: head,
                                input_span: value.span(),
                            });
                        }

                        let end = if let PipelineData::Value(Value::List { vals, .. }, _) = &input {
                            end.min((vals.len() as i64) - 1)
                        } else {
                            end
                        };

                        rows_to_drop.extend((start as usize)..=(end as usize));
                    }
                    Range::FloatRange(_) => {
                        return Err(ShellError::UnsupportedInput {
                            msg: "float range not supported".into(),

Review comment (security):
this isn't correct, it will ignore any other indices/ranges other than the unbounded range. in this example everything should be dropped (since there are less than 100 files in the nushell source dir) but none of them are dropped because only the `999..` range is taken into consideration

```nushell
ls | drop nth 0..100 999.. 
# => ╭────┬─────────────────────┬──────┬───────────┬───────────────╮
# => │  # │        name         │ type │   size    │   modified    │
# => ├────┼─────────────────────┼──────┼───────────┼───────────────┤
# => │  0 │ CITATION.cff        │ file │     812 B │ 3 months ago  │
# => │  1 │ CODE_OF_CONDUCT.md  │ file │   3.3 KiB │ 6 months ago  │
# => │  2 │ CONTRIBUTING.md     │ file │  10.9 KiB │ 4 days ago    │
# => │  3 │ Cargo.lock          │ file │ 205.3 KiB │ 4 minutes ago │
# => │  4 │ Cargo.toml          │ file │   9.5 KiB │ 4 minutes ago │
# => │  5 │ Cross.toml          │ file │     666 B │ 3 months ago  │
# => │  6 │ LICENSE             │ file │   1.0 KiB │ a week ago    │
# => │  7 │ README.md           │ file │  12.1 KiB │ 4 days ago    │
# => │  8 │ SECURITY.md         │ file │   2.6 KiB │ 3 months ago  │
# => │  9 │ assets              │ dir  │   4.0 KiB │ 3 months ago  │
# => │ 10 │ benches             │ dir  │   4.0 KiB │ 4 days ago    │
# => │ 11 │ clippy              │ dir  │   4.0 KiB │ 3 months ago  │
# => │ 12 │ crates              │ dir  │   4.0 KiB │ 4 days ago    │
# => │ 13 │ devdocs             │ dir  │   4.0 KiB │ 4 days ago    │
# => │ 14 │ docker              │ dir  │   4.0 KiB │ a week ago    │
# => │ 15 │ rust-toolchain.toml │ file │   1.0 KiB │ 4 days ago    │
# => │ 16 │ scripts             │ dir  │   4.0 KiB │ 4 days ago    │
# => │ 17 │ src                 │ dir  │   4.0 KiB │ 4 days ago    │
# => │ 18 │ target              │ dir  │   4.0 KiB │ 2 days ago    │
# => │ 19 │ tests               │ dir  │   4.0 KiB │ 3 months ago  │
# => │ 20 │ toolkit.nu          │ file │  20.8 KiB │ a week ago    │
# => │ 21 │ typos.toml          │ file │     574 B │ 4 days ago    │
# => │ 22 │ wix                 │ dir  │   4.0 KiB │ a day ago     │
# => ╰────┴─────────────────────┴──────┴───────────┴───────────────╯
```

Code after:
            current: 0,
        }
        .into_pipeline_data_with_metadata(head, engine_state.signals().clone(), metadata))
    }
}

fn get_rows_to_drop(
    args: &[Value],
    head: Span,
) -> Result<(VecDeque<usize>, Option<usize>), ShellError> {
    let mut rows_to_drop = Vec::new();
    let mut min_unbounded_start: Option<usize> = None;

    for value in args {
        if let Ok(i) = value.as_int() {
            if i < 0 {
                return Err(ShellError::UnsupportedInput {
                    msg: "drop nth accepts only positive ints".into(),
                    input: "value originates from here".into(),
                    msg_span: head,
                    input_span: value.span(),
                });
            }
            rows_to_drop.push(i as usize);
        } else if let Ok(range) = value.as_range() {
            match range {
                Range::IntRange(range) => {
                    let start = range.start();
                    if start < 0 {
                        return Err(ShellError::UnsupportedInput {
                            msg: "drop nth accepts only positive ints".into(),
                            input: "value originates from here".into(),
                            msg_span: head,
                            input_span: value.span(),
                        });
                    }

                    match range.end() {
                        Bound::Included(end) => {
                            if end < start {
                                return Err(ShellError::UnsupportedInput {
                                    msg: "The upper bound must be greater than or equal to the lower bound".into(),
                                    input: "value originates from here".into(),
                                    msg_span: head,
                                    input_span: value.span(),
                                });
                            }
                            rows_to_drop.extend((start as usize)..=(end as usize));
                        }
                        Bound::Excluded(end) => {
                            if end <= start {