[libdvdnav-devel] [Git][videolan/libdvdread][master] 4 commits: bitreader: replace runtime check on number of bits
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Sat Aug 15 21:40:52 UTC 2026
Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdread
Commits:
e2bc9c95 by Steve Lhomme at 2026-08-15T23:40:17+02:00
bitreader: replace runtime check on number of bits
With GCC we can check the constant values are not bigger than 32 at
compile time.
- - - - -
daa9277e by Steve Lhomme at 2026-08-15T23:40:17+02:00
bitreader: forbid reading 0 bits with dvdread_getbits
Just in case.
- - - - -
d30059e7 by Steve Lhomme at 2026-08-15T23:40:17+02:00
bitreader: only call dvdread_getbits() with constant values
There is usage in DVD for variable size reading. And even though it may still
be a choice between a couple of values which can be handled with constants.
- - - - -
9e781eaa by Steve Lhomme at 2026-08-15T23:40:17+02:00
CI: disable optimizations for the Debian build
We don't use the binaries so it does not matter. But with optimizations
some code checks may be optimized out.
- - - - -
3 changed files:
- .gitlab-ci.yml
- src/bitreader.c
- src/dvdread/bitreader.h
Changes:
=====================================
.gitlab-ci.yml
=====================================
@@ -11,7 +11,7 @@ build-debian:
- docker
- amd64
script:
- - meson setup build -Dwarning_level=3 -Dextra_checks=true
+ - meson setup build -Dwarning_level=3 -Dextra_checks=true --optimization plain
- meson compile -C build
build-raspberry:
=====================================
src/bitreader.c
=====================================
@@ -37,13 +37,9 @@ int dvdread_getbits_init(getbits_state_t *state, const uint8_t *start) {
/* Non-optimized getbits. */
/* This can easily be optimized for particular platforms. */
-uint32_t dvdread_getbits(getbits_state_t *state, uint32_t number_of_bits) {
+uint32_t (dvdread_getbits)(getbits_state_t *state, uint32_t number_of_bits) {
uint32_t result=0;
uint8_t byte=0;
- if (number_of_bits > 32) {
- printf("Number of bits > 32 in getbits\n");
- abort();
- }
if ((state->bit_position) > 0) { /* Last getbits left us in the middle of a byte. */
if (number_of_bits > (8-state->bit_position)) { /* this getbits will span 2 or more bytes. */
=====================================
src/dvdread/bitreader.h
=====================================
@@ -36,6 +36,17 @@ typedef struct {
DVDREAD_API int dvdread_getbits_init(getbits_state_t *state, const uint8_t *start);
DVDREAD_API uint32_t dvdread_getbits(getbits_state_t *state, uint32_t number_of_bits);
+#if defined(__GNUC__) && !defined(__COVERITY__)
+
+__attribute__((error("dvdread_getbits requesting too many bits")))
+uint32_t dvdread_getbits_toomany( getbits_state_t *, size_t );
+
+// check the constant values are not bigger than 32 bits
+# define dvdread_getbits(s,b) \
+ ((__builtin_constant_p(b) && b <= 32 && b > 0) ? (dvdread_getbits)(s,b) : dvdread_getbits_toomany(s, b))
+
+#endif
+
#ifdef __cplusplus
};
#endif
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/32d2392bc8ac4530b0873a6aa8ce4e44f8472c8d...9e781eaa2894f73ba96386bc6a9ac96975620cf9
--
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/32d2392bc8ac4530b0873a6aa8ce4e44f8472c8d...9e781eaa2894f73ba96386bc6a9ac96975620cf9
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