[libdvdnav-devel] [Git][videolan/libdvdread][master] 5 commits: ifo_read: remove aborts on dvdread_getbits_init() calls
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Wed Dec 2 14:59:55 UTC 2026
Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdread
Commits:
1c1723cc by Steve Lhomme at 2026-12-02T15:56:43+01:00
ifo_read: remove aborts on dvdread_getbits_init() calls
We know we are not passing a NULL state nor a NULL buffer. They are both in the stack.
- - - - -
c5200170 by Steve Lhomme at 2026-12-02T15:56:43+01:00
nav_read: replace checks for dvdread_getbits_init() error on external buffer check
The getbits_state_t is always in the stack, non-NULL.
This way dvdread_getbits_init() can't fail.
- - - - -
f4e58f5b by Steve Lhomme at 2026-12-02T15:56:43+01:00
bitreader: check the state and start parameter are not NULL with nonnull attribute
Now it issues a warning when check state and start for NULL.
This is available at least with GCC 5 and Clang 4.
- - - - -
a3f1725f by Steve Lhomme at 2026-12-02T15:56:43+01:00
nav_read: mark navRead public API's a requiring a non null buffer
This is available at least with GCC 5 and Clang 4.
- - - - -
925cbd34 by Steve Lhomme at 2026-12-02T15:56:43+01:00
bitreader: remove always false test in dvdread_getbits_init()
All the calls from libdvdread are either never true or checked before.
- - - - -
5 changed files:
- src/bitreader.c
- src/dvdread/bitreader.h
- src/dvdread/nav_read.h
- src/ifo_read.c
- src/nav_read.c
Changes:
=====================================
src/bitreader.c
=====================================
@@ -28,7 +28,6 @@
#include "dvdread/bitreader.h"
int dvdread_getbits_init(getbits_state_t *state, const uint8_t *start) {
- if ((state == NULL) || (start == NULL)) return 0;
state->start = start;
state->bit_position = 0;
state->byte_position = 0;
=====================================
src/dvdread/bitreader.h
=====================================
@@ -33,7 +33,13 @@ typedef struct {
uint32_t bit_position;
} getbits_state_t;
-DVDREAD_API int dvdread_getbits_init(getbits_state_t *state, const uint8_t *start);
+#if (defined(__GNUC__) || defined(__clang__)) && !defined(__COVERITY__)
+# define DVD_BIT_INIT_NONNULL __attribute__((nonnull (1, 2)))
+#else
+# define DVD_BIT_INIT_NONNULL
+#endif
+
+DVDREAD_API int dvdread_getbits_init(getbits_state_t *state, const uint8_t *start) DVD_BIT_INIT_NONNULL;
DVDREAD_API uint32_t dvdread_getbits(getbits_state_t *state, uint32_t number_of_bits);
#if defined(__GNUC__) && !defined(__COVERITY__)
=====================================
src/dvdread/nav_read.h
=====================================
@@ -32,14 +32,21 @@
extern "C" {
#endif
+#if (defined(__GNUC__) || defined(__clang__)) && !defined(__COVERITY__)
+# define DVD_NAVREAD_NONNULL __attribute__((nonnull (2)))
+#else
+# define DVD_NAVREAD_NONNULL
+#endif
+
+
/**
* Reads the PCI packet data pointed to into th pci struct.
*
* @param pci Pointer to the PCI data structure to be filled in.
- * @param buffer Pointer to the buffer of the on disc PCI data
+ * @param buffer Pointer to the buffer of the on disc PCI data, can't be NULL
* containing at least 790 bytes.
*/
-DVDREAD_API void navRead_PCI(pci_t *, unsigned char *);
+DVDREAD_API void navRead_PCI(pci_t *, unsigned char *) DVD_NAVREAD_NONNULL;
/**
* Reads the still picture NAV PCI packet data pointed to into th pci struct.
@@ -48,16 +55,16 @@ DVDREAD_API void navRead_PCI(pci_t *, unsigned char *);
* @param buffer Pointer to the buffer of the on disc PCI data
* containing at least 694 bytes.
*/
-DVDREAD_API void navRead_ASV_PCI(pci_t *, unsigned char *);
+DVDREAD_API void navRead_ASV_PCI(pci_t *, unsigned char *) DVD_NAVREAD_NONNULL;
/**
* Reads the DSI packet data pointed to into dsi struct.
*
* @param dsi Pointer to the DSI data structure to be filled in.
- * @param buffer Pointer to the buffer of the on disc DSI data
+ * @param buffer Pointer to the buffer of the on disc DSI data, can't be NULL
* containing at least 674 bytes.
*/
-DVDREAD_API void navRead_DSI(dsi_t *, unsigned char *);
+DVDREAD_API void navRead_DSI(dsi_t *, unsigned char *) DVD_NAVREAD_NONNULL;
#ifdef __cplusplus
};
=====================================
src/ifo_read.c
=====================================
@@ -222,7 +222,7 @@ static void read_video_attr(video_attr_t *va) {
uint8_t buf[sizeof(video_attr_t)];
memcpy(buf, va, sizeof(video_attr_t));
- if (!dvdread_getbits_init(&state, buf)) abort();
+ dvdread_getbits_init(&state, buf);
va->mpeg_version = dvdread_getbits(&state, 2);
va->video_format = dvdread_getbits(&state, 2);
va->display_aspect_ratio = dvdread_getbits(&state, 2);
@@ -241,7 +241,7 @@ static void read_audio_attr(audio_attr_t *aa) {
uint8_t buf[sizeof(audio_attr_t)];
memcpy(buf, aa, sizeof(audio_attr_t));
- if (!dvdread_getbits_init(&state, buf)) abort();
+ dvdread_getbits_init(&state, buf);
aa->audio_format = dvdread_getbits(&state, 3);
aa->multichannel_extension = dvdread_getbits(&state, 1);
aa->lang_type = dvdread_getbits(&state, 2);
@@ -266,7 +266,7 @@ static void read_multichannel_ext(multichannel_ext_t *me) {
uint8_t buf[sizeof(multichannel_ext_t)];
memcpy(buf, me, sizeof(multichannel_ext_t));
- if (!dvdread_getbits_init(&state, buf)) abort();
+ dvdread_getbits_init(&state, buf);
me->zero1 = dvdread_getbits(&state, 7);
me->ach0_gme = dvdread_getbits(&state, 1);
me->zero2 = dvdread_getbits(&state, 7);
@@ -293,7 +293,7 @@ static void read_subp_attr(subp_attr_t *sa) {
uint8_t buf[sizeof(subp_attr_t)];
memcpy(buf, sa, sizeof(subp_attr_t));
- if (!dvdread_getbits_init(&state, buf)) abort();
+ dvdread_getbits_init(&state, buf);
sa->code_mode = dvdread_getbits(&state, 3);
sa->zero1 = dvdread_getbits(&state, 3);
sa->type = dvdread_getbits(&state, 2);
@@ -308,7 +308,7 @@ static void read_user_ops(user_ops_t *uo) {
uint8_t buf[sizeof(user_ops_t)];
memcpy(buf, uo, sizeof(user_ops_t));
- if (!dvdread_getbits_init(&state, buf)) abort();
+ dvdread_getbits_init(&state, buf);
uo->zero = dvdread_getbits(&state, 7);
uo->video_pres_mode_change = dvdread_getbits(&state, 1);
uo->karaoke_audio_pres_mode_change = dvdread_getbits(&state, 1);
@@ -342,7 +342,7 @@ static void read_pgci_srp(pgci_srp_t *ps) {
uint8_t buf[sizeof(pgci_srp_t)];
memcpy(buf, ps, sizeof(pgci_srp_t));
- if (!dvdread_getbits_init(&state, buf)) abort();
+ dvdread_getbits_init(&state, buf);
ps->entry_id = dvdread_getbits(&state, 8);
ps->block_mode = dvdread_getbits(&state, 2);
ps->block_type = dvdread_getbits(&state, 2);
@@ -356,7 +356,7 @@ static void read_cell_playback(cell_playback_t *cp) {
uint8_t buf[sizeof(cell_playback_t)];
memcpy(buf, cp, sizeof(cell_playback_t));
- if (!dvdread_getbits_init(&state, buf)) abort();
+ dvdread_getbits_init(&state, buf);
cp->block_mode = dvdread_getbits(&state, 2);
cp->block_type = dvdread_getbits(&state, 2);
cp->seamless_play = dvdread_getbits(&state, 1);
@@ -386,7 +386,7 @@ static void read_playback_type(playback_type_t *pt) {
uint8_t buf[sizeof(playback_type_t)];
memcpy(buf, pt, sizeof(playback_type_t));
- if (!dvdread_getbits_init(&state, buf)) abort();
+ dvdread_getbits_init(&state, buf);
pt->zero_1 = dvdread_getbits(&state, 1);
pt->multi_or_random_pgc_title = dvdread_getbits(&state, 1);
pt->jlc_exists_in_cell_cmd = dvdread_getbits(&state, 1);
=====================================
src/nav_read.c
=====================================
@@ -70,7 +70,8 @@ static void read_hli(hli_t *hli, getbits_state_t *state);
void navRead_PCI(pci_t *pci, unsigned char *buffer) {
int32_t i;
getbits_state_t state;
- if (!getbits_init(&state, buffer)) abort(); /* Passed NULL pointers */
+ if (buffer == NULL) abort(); /* Passed NULL pointers */
+ getbits_init(&state, buffer);
/* pci_t is no longer packed, so it now has padding bytes that the field by
* field parsing below never writes; clear them to keep the whole structure
@@ -134,7 +135,8 @@ void navRead_PCI(pci_t *pci, unsigned char *buffer) {
/* the still picture NAV packet, substream 0x02, has no PCI general information */
void navRead_ASV_PCI(pci_t *pci, unsigned char *buffer) {
getbits_state_t state;
- if (!getbits_init(&state, buffer)) abort();
+ if (buffer == NULL) abort(); /* Passed NULL pointers */
+ getbits_init(&state, buffer);
memset(pci, 0, sizeof(*pci));
read_hli(&pci->hli, &state);
}
@@ -257,7 +259,8 @@ static void read_hli(hli_t *hli, getbits_state_t *state) {
void navRead_DSI(dsi_t *dsi, unsigned char *buffer) {
int i;
getbits_state_t state;
- if (!getbits_init(&state, buffer)) abort(); /* Passed NULL pointers */
+ if (buffer == NULL) abort(); /* Passed NULL pointers */
+ getbits_init(&state, buffer);
/* dsi dsi gi */
dsi->dsi_gi.nv_pck_scr = getbits(&state, 32 );
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/c10c95b69f1e677015ef0ef63d2f526ebaa075e8...925cbd346e95bc977dd6278b47decd27fe591e61
--
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/c10c95b69f1e677015ef0ef63d2f526ebaa075e8...925cbd346e95bc977dd6278b47decd27fe591e61
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