[libdvdnav-devel] [Git][videolan/libdvdread][master] 7 commits: nav_types: make btin_t not packed

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Wed Jul 29 12:31:45 UTC 2026



Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdread


Commits:
12916a31 by Steve Lhomme at 2026-07-29T09:01:59+02:00
nav_types: make btin_t not packed

The use of bitfields of 10 bits makes the use of `unsigned char` impossible.
That means the compiler might use more bits than expected for the 4*12 bits.
This is the case with MS-compatible compilers. We cannot guarantee that the
btin_t will use the same 10 octets as used in the binary blob.

In the end btin_t is not read as a packed structure but bit by bit in
navRead_PCI().

- - - - -
07da473c by Steve Lhomme at 2026-07-29T09:01:59+02:00
nav_types: make hli_t and pci_t not packed

They depends on the packing of btni_t. Since btni_t is no longer packed, they
cannot be packed anymore.

This is not a problem as they are read bit by bit in navRead_PCI().

- - - - -
8cd2e981 by Saifelden Mohamed Ismail at 2026-07-29T15:25:13+03:00
nav_read: assert during compilation if nav structure sizes are not respected

- - - - -
309850e4 by Saifelden Mohamed Ismail at 2026-07-29T15:25:13+03:00
ifo_types: stop forcing gcc-style bitfield packing

- - - - -
cd71b392 by Saifelden Mohamed Ismail at 2026-07-29T15:25:13+03:00
nav_types: make pragma packing match the attribute packing

- - - - -
d7a0ee6a by Saifelden Mohamed Ismail at 2026-07-29T15:25:13+03:00
ifo_types: add missing defines for some packed structure sizes

- - - - -
42ace18e by Saifelden Mohamed Ismail at 2026-07-29T15:25:13+03:00
ifo_read: assert the remaining packed structure sizes during compilation

- - - - -


4 changed files:

- src/dvdread/ifo_types.h
- src/dvdread/nav_types.h
- src/ifo_read.c
- src/nav_read.c


Changes:

=====================================
src/dvdread/ifo_types.h
=====================================
@@ -30,11 +30,7 @@
 
 #if defined(__GNUC__)
 # if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 95)
-#  if (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) && !defined(__clang__)
-#   define ATTRIBUTE_PACKED __attribute__ ((packed,gcc_struct))
-#  else
-#   define ATTRIBUTE_PACKED __attribute__ ((packed))
-#  endif
+#  define ATTRIBUTE_PACKED __attribute__ ((packed))
 #  define PRAGMA_PACK 0
 # endif
 #endif
@@ -1191,16 +1187,19 @@ typedef struct {
 typedef struct {
   uint8_t audio_attr[3];
 } ATTRIBUTE_PACKED audio_attr_vr_t;
+#define AUDIO_ATTR_VR_SIZE 3U
 
 typedef struct {
   uint8_t pgtm[5];
 } ATTRIBUTE_PACKED pgtm_t;
+#define PGTM_SIZE 5U
 
 /* used throughout the program for timestamps */
 typedef struct {
   uint32_t ptm;
   uint16_t ptm_extra; /* extra to DSI pkts */
 } ATTRIBUTE_PACKED ptm_t;
+#define PTM_SIZE 6U
 
 typedef struct {
   uint8_t  data[12];


=====================================
src/dvdread/nav_types.h
=====================================
@@ -43,6 +43,10 @@
 /* Remove this */
 #define DSI_START_BYTE 1031
 
+#if PRAGMA_PACK
+#pragma pack(1)
+#endif
+
 /**
  * PCI General Information
  */
@@ -108,6 +112,12 @@ typedef struct {
   uint32_t btn_coli[3][2];  /**< [button color number-1][select:0/action:1] */
 } ATTRIBUTE_PACKED btn_colit_t;
 
+/* btni_t, hli_t and pci_t are not read as packed structures but bit by bit
+ * in navRead_PCI(), they must not be packed */
+#if PRAGMA_PACK
+#pragma pack()
+#endif
+
 /**
  * Button Information
  *
@@ -135,7 +145,7 @@ typedef struct {
   unsigned int zero6            : 2;  /**< reserved */
   unsigned int right            : 6;  /**< button index when pressing right */
   vm_cmd_t cmd;
-} ATTRIBUTE_PACKED btni_t;
+} btni_t;
 
 /**
  * Highlight Information
@@ -144,7 +154,7 @@ typedef struct {
   hl_gi_t     hl_gi;
   btn_colit_t btn_colit;
   btni_t      btnit[36];
-} ATTRIBUTE_PACKED hli_t;
+} hli_t;
 
 /**
  * PCI packet
@@ -154,7 +164,11 @@ typedef struct {
   nsml_agli_t nsml_agli;
   hli_t       hli;
   uint8_t     zero1[189];
-} ATTRIBUTE_PACKED pci_t;
+} pci_t;
+
+#if PRAGMA_PACK
+#pragma pack(1)
+#endif
 
 
 


=====================================
src/ifo_read.c
=====================================
@@ -207,6 +207,21 @@ CHECK_STRUCT_SIZE(pgc_gi_t,               2, PGC_GI_SIZE);
 CHECK_STRUCT_SIZE(ud_pgcit_t,             3, UD_PGCIT_SIZE);
 CHECK_STRUCT_SIZE(m_c_gi_t,               1, M_C_GI_SIZE);
 CHECK_STRUCT_SIZE(m_c_epi_t,              0, M_C_EPI_SIZE);
+CHECK_STRUCT_SIZE(ats_pg_asv_pbi_srp_t,   0, ATS_PG_ASV_PBI_SRP_SIZE);
+CHECK_STRUCT_SIZE(asv_dlist_t,            0, ASV_DLIST_SIZE);
+CHECK_STRUCT_SIZE(asvu_gi_t,              0, ASVU_GI_SIZE);
+CHECK_STRUCT_SIZE(asvs_mat_t,             1, ASVS_MAT_SIZE);
+CHECK_STRUCT_SIZE(audio_attr_vr_t,        0, AUDIO_ATTR_VR_SIZE);
+CHECK_STRUCT_SIZE(cprm_info_t,            0, CPRM_INFO_SIZE);
+CHECK_STRUCT_SIZE(pgtm_t,                 0, PGTM_SIZE);
+CHECK_STRUCT_SIZE(ptm_t,                  0, PTM_SIZE);
+CHECK_STRUCT_SIZE(time_info_t,            0, TIME_INFO_SIZE);
+CHECK_STRUCT_SIZE(vobu_info_t,            0, VOBU_INFO_SIZE);
+CHECK_STRUCT_SIZE(vobu_map_t,             2, VOBU_MAP_SIZE);
+CHECK_STRUCT_SIZE(vvob_t,                 0, VVOB_SIZE);
+CHECK_STRUCT_SIZE(adj_vob_t,              0, ADJ_VOB_SIZE);
+CHECK_STRUCT_SIZE(vob_format_t,           0, VOB_FORMAT_SIZE);
+CHECK_STRUCT_SIZE(ud_pgci_t,              0, UD_PGCI_SIZE);
 
 static void read_video_attr(video_attr_t *va) {
   getbits_state_t state;


=====================================
src/nav_read.c
=====================================
@@ -22,6 +22,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <assert.h>
 #include <string.h>
 #include <inttypes.h>
 
@@ -34,6 +35,29 @@
 #define getbits_init dvdread_getbits_init
 #define getbits dvdread_getbits
 
+#define STRINGIFY_NAME( z )   STRINGIFY_NAME_( z )
+#define STRINGIFY_NAME_( z ) #z
+
+/* nav structures are filled bit by bit but exposed in the public API, their
+ * layout must not depend on the compiler or its bitfield packing scheme */
+#define CHECK_NAV_STRUCT_SIZE(strt, size) \
+  static_assert(sizeof(strt) == size, STRINGIFY_NAME(strt) " not " STRINGIFY_NAME(size) " bytes")
+
+CHECK_NAV_STRUCT_SIZE(pci_gi_t,       60);
+CHECK_NAV_STRUCT_SIZE(nsml_agli_t,    36);
+CHECK_NAV_STRUCT_SIZE(hl_gi_t,        22);
+CHECK_NAV_STRUCT_SIZE(btn_colit_t,    24);
+CHECK_NAV_STRUCT_SIZE(btni_t,         20);
+CHECK_NAV_STRUCT_SIZE(hli_t,         768);
+CHECK_NAV_STRUCT_SIZE(pci_t,        1056);
+CHECK_NAV_STRUCT_SIZE(dsi_gi_t,       32);
+CHECK_NAV_STRUCT_SIZE(sml_pbi_t,     148);
+CHECK_NAV_STRUCT_SIZE(sml_agl_data_t,  6);
+CHECK_NAV_STRUCT_SIZE(sml_agli_t,     54);
+CHECK_NAV_STRUCT_SIZE(vobu_sri_t,    168);
+CHECK_NAV_STRUCT_SIZE(synci_t,       144);
+CHECK_NAV_STRUCT_SIZE(dsi_t,        1017);
+
 #define CHECK_VALUE(arg)\
   if(!(arg)) {\
     DVDReadLog(NULL, NULL, DVD_LOGGER_LEVEL_WARN,\



View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/228ddaa6f135e615332d0c86f026b9cdcaffa586...42ace18eaf15e1c929ed06fbfd3b40fb409b8c8c

-- 
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/228ddaa6f135e615332d0c86f026b9cdcaffa586...42ace18eaf15e1c929ed06fbfd3b40fb409b8c8c
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the libdvdnav-devel mailing list