Re: TOT decode - bug

Angelo Schiavone <[email protected]>
Newsgroups gmane.comp.video.videolan.libdvbpsi.devel
Message-ID <CADyCdYe_5mXVO0m9BOMNiLuaZ8r3LSn4eZE4+vPePZZqSOM=Og@mail.gmail.com>
here is the git patch.
thanks
Angelo

2013/1/23 Jean-Paul Saman <[email protected]>

> Angelo,
>
> Could you please sent a patch against git://git.videolan.org/libdvbpsi.gitrepository using the git tool?
>
> It makes reviewing your changes easier.
>
> Thank you very much.
>
> Kind regards,
> Jean-Paul Saman
>
>
> On Tue, Jan 22, 2013 at 5:03 PM, Angelo Schiavone <
> [email protected]> wrote:
>
>> Hi again, TOT table does not decode correctly, it miss descriptors in the
>> descriptors loop.
>> That's because  p_byte += 7; is incremented after p_end is calculated
>>
>> p_end = p_byte + (   ((uint16_t)(p_section->p_payload_start[5] & 0x0f) << 8)
>>
>>                                  | p_section->p_payload_start[6]);
>>
>>
>> Instead it should happen before p_end assignment, attached the correct version.
>>
>>
>> void dvbpsi_tot_sections_decode(dvbpsi_t* p_dvbpsi, dvbpsi_tot_t* p_tot,
>>
>>                               dvbpsi_psi_section_t* p_section)
>>
>> {
>>
>>     if (p_section)
>>
>>     {
>>
>>         uint8_t* p_byte;
>>
>>          if (!dvbpsi_tot_section_valid(p_dvbpsi, p_section))
>>
>>             return;
>>
>>          p_byte = p_section->p_payload_start;
>>
>>         if (p_byte + 5 <= p_section->p_payload_end)
>>
>>         {
>>
>>             p_tot->i_utc_time = ((uint64_t)p_byte[0] << 32) |
>>
>>                                 ((uint64_t)p_byte[1] << 24) |
>>
>>                                 ((uint64_t)p_byte[2] << 16) |
>>
>>                                 ((uint64_t)p_byte[3] << 8) |
>>
>>                                  (uint64_t)p_byte[4];
>>
>>         }
>>
>>          /* If we have a TOT, extract the descriptors */
>>
>>         if (p_section->i_table_id == 0x73)
>>
>>         {
>>
>>             uint8_t* p_end;
>>
>>             p_byte += 7;
>>
>>             p_end = p_byte + (   ((uint16_t)(p_section->p_payload_start[5] & 0x0f) << 8)
>>
>>                                  | p_section->p_payload_start[6]);
>>
>>             while (p_byte+2 <= p_end)
>>
>>             {
>>
>>                 uint8_t i_tag = p_byte[0];
>>
>>                 uint8_t i_length = p_byte[1];
>>
>>                 if (i_length + 2 <= p_section->p_payload_end - p_byte)
>>
>>                     dvbpsi_tot_descriptor_add(p_tot, i_tag, i_length, p_byte + 2);
>>
>>                 p_byte += 2 + i_length;
>>
>>             }
>>
>>         }
>>
>>     }
>>
>> }
>>
>>
>> _______________________________________________
>> libdvbpsi-devel mailing list
>> [email protected]
>> http://mailman.videolan.org/listinfo/libdvbpsi-devel
>>
>>
>

_______________________________________________
libdvbpsi-devel mailing list
[email protected]
http://mailman.videolan.org/listinfo/libdvbpsi-devel
fix_tot_bat_nit_cat_decode_tot_crc.patch (application/octet-stream, 4.5 KB)
From 7b8da2568eb690e04109a7118ce81b6720561474 Mon Sep 17 00:00:00 2001
From: Angelo Schiavone <[email protected]>
Date: Wed, 23 Jan 2013 14:35:15 +0100
Subject: [PATCH 1/2] 2 bugs in decoding BAT and NIT

---
 src/tables/bat.c |    6 ++----
 src/tables/nit.c |    2 +-
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/tables/bat.c b/src/tables/bat.c
index 25f2ae3..b855d9f 100644
--- a/src/tables/bat.c
+++ b/src/tables/bat.c
@@ -487,18 +487,16 @@ void dvbpsi_bat_sections_decode(dvbpsi_bat_t* p_bat,
       p_byte += 2 + i_length;
     }
 
-    p_end = p_byte + ( ((uint16_t)(p_byte[0] & 0x0f) << 8)
+    p_end = 2+p_byte + ( ((uint16_t)(p_byte[0] & 0x0f) << 8)
                        | p_byte[1]);
     if(p_end > p_section->p_payload_end)
     {
         p_end = p_section->p_payload_end;
     }
-
+    p_byte += 2;
     /* - TSs */
     for(; p_byte + 6 <= p_end;)
     {
-      p_byte += 2;
-
       uint16_t i_ts_id = ((uint16_t)p_byte[0] << 8) | p_byte[1];
       uint16_t i_orig_network_id = ((uint16_t)p_byte[2] << 8) | p_byte[3];
       uint16_t i_transport_descriptors_length = ((uint16_t)(p_byte[4] & 0x0f) << 8) | p_byte[5];
diff --git a/src/tables/nit.c b/src/tables/nit.c
index c3d042f..4725912 100644
--- a/src/tables/nit.c
+++ b/src/tables/nit.c
@@ -473,7 +473,7 @@ void dvbpsi_nit_sections_decode(dvbpsi_nit_t* p_nit,
             p_byte += 2 + i_length;
         }
 
-        p_end = p_byte + (   ((uint16_t)(p_byte[0] & 0x0f) << 8)
+        p_end = 2 + p_byte + (   ((uint16_t)(p_byte[0] & 0x0f) << 8)
                        | p_byte[1]);
         if (p_end > p_section->p_payload_end)
         {
-- 
1.7.9.5


From e6c580fd7337bf503b97d679794d684cb048c967 Mon Sep 17 00:00:00 2001
From: Angelo Schiavone <[email protected]>
Date: Wed, 23 Jan 2013 15:04:21 +0100
Subject: [PATCH 2/2] fixes TOT decode, TOT crc calculation, CAT decode

---
 src/psi.c        |    5 ++---
 src/tables/cat.c |    2 +-
 src/tables/tot.c |    9 ++-------
 3 files changed, 5 insertions(+), 11 deletions(-)

diff --git a/src/psi.c b/src/psi.c
index e1860dc..22c92bd 100644
--- a/src/psi.c
+++ b/src/psi.c
@@ -137,18 +137,17 @@ error:
  *****************************************************************************/
 bool dvbpsi_ValidPSISection(dvbpsi_psi_section_t* p_section)
 {
-    if (p_section->b_syntax_indicator)
+// TOT has table_id  0x73
+    if ( (p_section->p_data[0]==0x73) || p_section->b_syntax_indicator)
     {
         /* Check the CRC_32 if b_syntax_indicator is false */
         uint32_t i_crc = 0xffffffff;
         uint8_t* p_byte = p_section->p_data;
-
         while(p_byte < p_section->p_payload_end + 4)
         {
             i_crc = (i_crc << 8) ^ dvbpsi_crc32_table[(i_crc >> 24) ^ (*p_byte)];
             p_byte++;
         }
-
         if (i_crc == 0)
             return true;
         else
diff --git a/src/tables/cat.c b/src/tables/cat.c
index b283eac..7b366b4 100644
--- a/src/tables/cat.c
+++ b/src/tables/cat.c
@@ -347,7 +347,7 @@ void dvbpsi_cat_sections_decode(dvbpsi_cat_t* p_cat, dvbpsi_psi_section_t* p_sec
     {
         /* CAT descriptors */
         p_byte = p_section->p_payload_start;
-        while (p_byte + 5 <= p_section->p_payload_end)
+        while (p_byte <= p_section->p_payload_end)
         {
             uint8_t i_tag = p_byte[0];
             uint8_t i_length = p_byte[1];
diff --git a/src/tables/tot.c b/src/tables/tot.c
index 0236ee4..a5e4cb5 100644
--- a/src/tables/tot.c
+++ b/src/tables/tot.c
@@ -438,10 +438,8 @@ void dvbpsi_tot_sections_decode(dvbpsi_t* p_dvbpsi, dvbpsi_tot_t* p_tot,
     if (p_section)
     {
         uint8_t* p_byte;
-
         if (!dvbpsi_tot_section_valid(p_dvbpsi, p_section))
             return;
-
         p_byte = p_section->p_payload_start;
         if (p_byte + 5 <= p_section->p_payload_end)
         {
@@ -451,17 +449,14 @@ void dvbpsi_tot_sections_decode(dvbpsi_t* p_dvbpsi, dvbpsi_tot_t* p_tot,
                                 ((uint64_t)p_byte[3] << 8) |
                                  (uint64_t)p_byte[4];
         }
-
         /* If we have a TOT, extract the descriptors */
         if (p_section->i_table_id == 0x73)
         {
             uint8_t* p_end;
-
+            p_byte += 7;
             p_end = p_byte + (   ((uint16_t)(p_section->p_payload_start[5] & 0x0f) << 8)
                                  | p_section->p_payload_start[6]);
-            p_byte += 7;
-
-            while (p_byte + 5 <= p_end)
+            while (p_byte+2 <= p_end)
             {
                 uint8_t i_tag = p_byte[0];
                 uint8_t i_length = p_byte[1];
-- 
1.7.9.5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.