Skip to content

Address range validation difference for line number command #234

Closed

Description

@sylvestre

Gnu:

 $ echo -e "line1\nline2\nline3" | sed -e "47,60="
  line1
  line2
  line3

with Rust:

  $ echo -e "line1\nline2\nline3" | ./target/debug/sed -e "47,60="
  sed: <script argument 1>:1:6: error: command = expects up to 1 address(es), found 2

Found with a fuzzer

Activity

  1. LoukasPap commented on Jan 10, 2026

    @LoukasPap
    Contributor

    Hello, I can work on it if it's OK!

  2. cakebaker commented on Jan 10, 2026

    @cakebaker
    Contributor

    @LoukasPap sure, go ahead!

  3. LoukasPap commented on Jan 11, 2026

    @LoukasPap
    Contributor

    The problem is in the code block below, where the = cmd_code supports only 1 address.

    sed/src/sed/compiler.rs

    Lines 1211 to 1213 in db58849

    '=' => Ok(CommandSpec {
    n_addr: 1,
    handler: compile_empty_command,

    Changing the supported addresses from 1 to 2 seems to fix the problem without breaking something else. I will make a MR soon.

  4. LoukasPap commented on Jan 11, 2026

    @LoukasPap
    Contributor

    I am searching where is the most suitable place to add a relative test case. Is under the address_ranges good?

    // Address ranges: One and two, numeric and pattern

  5. sylvestre commented on Jan 11, 2026

    @sylvestre
    SponsorContributorAuthor

    sounds good

  6. LoukasPap commented on Jan 11, 2026

    @LoukasPap
    Contributor

    Eventually, I found it better to write them under here, to their corresponding cmd_code:

    // =, l commands
    check_output!(number_continuous, ["/l2_/=", LINES1, LINES2]);
    check_output!(number_separate, ["-s", "/l._8/=", LINES1, LINES2]);

    I've added two tests from which only the number_range_out_of_bounds works (input is same to output). For the first one (number_range), I am sure the expected outputs are correct but the test fails without pointing out any fault.

    check_output!(number_range, ["-e", "3,5=", LINES1]);
    check_output!(number_range_out_of_bounds, ["-e", "47,60=", LINES1]);

    Is this problem known? I checked the number_continuous & number_separate cases and they were failing too.

  7. LoukasPap commented on Jan 12, 2026

    @LoukasPap
    Contributor

    @sylvestre Should I create a different branch (named with issue ID) on my forked repository before MR, or just push to main?

  8. sylvestre commented on Jan 12, 2026

    @sylvestre
    SponsorContributorAuthor

    please create a pr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions