Skip to content

Split enters endless loop #14118

Closed
Closed

Description

@mtvb
# ./coreutils --version
coreutils 0.10.0 (multi-call binary)

compiled from commit 71ebb922b358273253ba6a868a4c2182bd39a0fe (latest)

# printf 'a' | ./coreutils split -n l/2
(endless loop)

Activity

  1. sylvestre commented on Aug 24, 2026

    @sylvestre
    SponsorContributor

    "fun" :)

  2. mtvb commented on Aug 24, 2026

    @mtvb
    ContributorAuthor

    If I may add some information I dug up:

    src/uu/split/src/split.rs

      let chunk_size_base     = num_bytes / num_chunks;
      let chunk_size_reminder = num_bytes % num_chunks;
      ...
      while num_bytes_should_be_written <= num_bytes_written {
          num_bytes_should_be_written +=
              chunk_size_base + (chunk_size_reminder > chunk_number) as u64;
          chunk_number += 1;
      }
    

    With chunk_size_base = 0, the increment is only the boolean term. Once chunk_number reaches chunk_size_reminder that term is 0 too, so num_bytes_should_be_written stops advancing while the loop condition stays true. Only chunk_number keeps counting.

  3. sylvestre commented on Aug 24, 2026

    @sylvestre
    SponsorContributor

    Look good. Don't hesitate to submit a pr with a test

  4. added a commit that references this issue on Aug 25, 2026
    0317808
  5. added a commit that references this issue on Sep 28, 2026
    17ac287
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions