Skip to content

Panic when calling pes.NewPESHeader #52

Open
@itsjamie

Description

While building a tool to do an analysis of MPEGTS for HLS delivery, ran into a panic while calling pes.NewPESHeader.

pes := new(pESHeader)
var err error

if CheckLength(pesBytes, "PES", 6) {

	pes.packetStartCodePrefix = uint32(pesBytes[0])<<16 | uint32(pesBytes[1])<<8 | uint32(pesBytes[2])

	pes.streamId = uint8(pesBytes[3])
	pes.pesPacketLength = uint16(pesBytes[4])<<8 | uint16(pesBytes[5])
--->	pes.dataAlignment = pesBytes[6]&0x04 != 0
	dataStartIndex := 6

The code panics on the pesBytes[6] check being out of bounds.

I think that CheckLength should be called with a value of seven in this case since it's checking the length of the byte array which is one-based, but the index is zero based.

Thank you for this code, it made getting started much easier!

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions