From e47b3a70d1837a7955c2de3ec0e32712b0725312 Mon Sep 17 00:00:00 2001
From: Quentin Renard <contact@asticode.com>
Date: Tue, 17 Sep 2019 09:51:00 +0200
Subject: [PATCH] Fixed PES data parsing

---
 data_pes.go      | 2 +-
 data_pes_test.go | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/data_pes.go b/data_pes.go
index 5bd64af..56c6823 100644
--- a/data_pes.go
+++ b/data_pes.go
@@ -123,7 +123,7 @@ func parsePESData(i *astibyte.Iterator) (d *PESData, err error) {
 
 	// Parse data
 	if d.Header != nil && d.Header.PacketLength > 0 {
-		if d.Data, err = i.NextBytes(int(d.Header.PacketLength)); err != nil {
+		if d.Data, err = i.NextBytes(int(d.Header.PacketLength)-dataStart); err != nil {
 			err = errors.Wrap(err, "astits: getting next bytes failed")
 			return
 		}
diff --git a/data_pes_test.go b/data_pes_test.go
index 63bebac..29c23c1 100644
--- a/data_pes_test.go
+++ b/data_pes_test.go
@@ -222,10 +222,10 @@ func TestParsePESSection(t *testing.T) {
 	// No optional header and specific packet length
 	d, err := parsePESData(astibyte.NewIterator(pesWithoutHeaderBytes()))
 	assert.NoError(t, err)
-	assert.Equal(t, d, pesWithoutHeader)
+	assert.Equal(t, pesWithoutHeader, d)
 
 	// Optional header and no specific header length
 	d, err = parsePESData(astibyte.NewIterator(pesWithHeaderBytes()))
 	assert.NoError(t, err)
-	assert.Equal(t, d, pesWithHeader)
+	assert.Equal(t, pesWithHeader, d)
 }