Skip to content

readSubStreamsInfo() panic "runtime error: index out of range [N] with length N" #400

@marktayl

Description

@marktayl

When id == idSize in readSubStreamsInfo(), you execute the loops:

        s.size = make([]uint64, files)
        k := 0

        for i := range s.streams {
            total := uint64(0)

            for j := uint64(1); j < s.streams[i]; j++ {
                if s.size[k], err = readUint64(r); err != nil {
                    return nil, err
                }

                total += s.size[k]
                k++
            }

            s.size[k] = folder[i].unpackSize() - total
            k++  // <--- SUSPECT
        }

        id, err = r.ReadByte()
        if err != nil {
            return nil, fmt.Errorf("readSubStreamsInfo: ReadByte error: %w", err)
        }

I have a sample 7z (I cannot give it to you) that has [25, 0, 0] files. This causes the s.size[k] to panic with the error "index out of range [25] with length 25", because it gets to k=25 when i==1 when processing the second folder, aka s.streams[1]. I believe that the k++ at the end of the outer loop, which I marked "SUSPECT", is where I believe the fault is - that increment is not required (proper k value incrementing is handled inside the for j loop).

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions