Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when calling pes.NewPESHeader #52

Open
itsjamie opened this issue Aug 2, 2017 · 2 comments
Open

Panic when calling pes.NewPESHeader #52

itsjamie opened this issue Aug 2, 2017 · 2 comments

Comments

@itsjamie
Copy link

itsjamie commented Aug 2, 2017

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!

@guygrigsby
Copy link
Collaborator

Thanks for the bug report and I am glad that gots has helped you get started.

There are 6 bytes that are shared at the beginning of all PES packets. packet_start_code_prefix is 3 bytes, stream_id is 1 byte, and PES_packet_length is 2 bytes. data_alignment_indicator is not always present. I think the right thing to do is to move pes.dataAlignment = pesBytes[6]&0x04 != 0 down into the conditional that checks if pes.optionalFieldsExist(). I'll look more into it soon.

@guygrigsby guygrigsby self-assigned this Aug 6, 2017
@tmm1
Copy link
Contributor

tmm1 commented May 12, 2018

Ping

@guygrigsby guygrigsby removed their assignment Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants