[libdvdnav-devel] [Git][videolan/libdvdread][master] dvd_reader: fall back to the BUP in DVDDiscID
Jean-Baptiste Kempf (@jbk)
gitlab at videolan.org
Wed Dec 2 10:18:43 UTC 2026
Jean-Baptiste Kempf pushed to branch master at VideoLAN / libdvdread
Commits:
159e4281 by Pierre Bogdanovscky at 2026-12-02T11:12:56+01:00
dvd_reader: fall back to the BUP in DVDDiscID
An IFO that exists but cannot be read made DVDDiscID() fail, while
ifoOpen() reads its BUP instead. Do the same when the BUP has the IFO's
size: it is meant to hold the same bytes, so the ID is unchanged.
A missing IFO is still skipped, and an unreadable BUP still means no ID.
Work item: #30400
- - - - -
2 changed files:
- src/dvd_reader.c
- src/dvdread/dvd_reader.h
Changes:
=====================================
src/dvd_reader.c
=====================================
@@ -2030,6 +2030,57 @@ ssize_t DVDFileSize( dvd_file_t *dvd_file )
return dvd_file->filesize;
}
+/* Adds the info file of title set [title] in [domain] to [ctx]: its IFO, or
+ * its BUP, which holds the same bytes. A BUP stands for its IFO only when
+ * [expected_size] - the IFO's - is its size too. [file_size], if not NULL,
+ * receives the file's size once it is opened.
+ * Returns 1 once added, 0 when there is no such file, -1 when it could not
+ * be read, -2 when memory ran out - no reason to try its backup. */
+static int DiscIDAddFile( dvd_reader_t *dvd, int title, dvd_read_domain_t domain,
+ ssize_t *file_size, ssize_t expected_size,
+ struct md5_s *ctx )
+{
+ dvd_file_t *dvd_file = DVDOpenFile( dvd, title, domain );
+ if( dvd_file == NULL )
+ return 0;
+
+ ssize_t bytes_read;
+ ssize_t size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
+ if( file_size != NULL )
+ *file_size = size;
+ if( expected_size > 0 && size != expected_size ) {
+ Log1(dvd, "DVDDiscId, backup of title set %d is %zd bytes, "
+ "not the %zd of its IFO", title, size, expected_size );
+ DVDCloseFile( dvd_file );
+ return -1;
+ }
+
+ char *buffer_base = malloc( size + 2048 );
+
+ if( buffer_base == NULL ) {
+ DVDCloseFile( dvd_file );
+ Log0(dvd, "DVDDiscId, failed to allocate memory for file read" );
+ return -2;
+ }
+
+ char *buffer = (char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);
+
+ bytes_read = DVDReadBytes( dvd_file, buffer, size );
+ if( bytes_read != size ) {
+ Log1(dvd, "DVDDiscId read returned %zd bytes"
+ ", wanted %zd", bytes_read, size );
+ DVDCloseFile( dvd_file );
+ free( buffer_base );
+ return -1;
+ }
+
+ AddMD5( ctx, buffer, size );
+
+ DVDCloseFile( dvd_file );
+ free( buffer_base );
+ return 1;
+}
+
int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
{
struct md5_s ctx;
@@ -2055,38 +2106,25 @@ int DVDDiscID( dvd_reader_t *dvd, unsigned char *discid )
title_sets = 10;
/* Go through the first IFO:s, in order, up until the tenth,
- * and md5sum them, i.e VIDEO_TS.IFO and VTS_0?_0.IFO */
+ * and md5sum them, i.e VIDEO_TS.IFO and VTS_0?_0.IFO. An IFO that
+ * cannot be read is replaced by its BUP, as ifoOpen() does: the same
+ * bytes, so the same ID. */
InitMD5( &ctx );
for( title = 0; title < title_sets; title++ ) {
- dvd_file_t *dvd_file = DVDOpenFile( dvd, title, DVD_READ_INFO_FILE );
- if( dvd_file != NULL ) {
- ssize_t bytes_read;
- ssize_t file_size = dvd_file->filesize * DVD_VIDEO_LB_LEN;
- char *buffer_base = malloc( file_size + 2048 );
-
- if( buffer_base == NULL ) {
- DVDCloseFile( dvd_file );
- Log0(dvd, "DVDDiscId, failed to allocate memory for file read" );
- return -1;
- }
-
- char *buffer = (char *)(((uintptr_t)buffer_base & ~((uintptr_t)2047)) + 2048);
-
- bytes_read = DVDReadBytes( dvd_file, buffer, file_size );
- if( bytes_read != file_size ) {
- Log1(dvd, "DVDDiscId read returned %zd bytes"
- ", wanted %zd", bytes_read, file_size );
- DVDCloseFile( dvd_file );
- free( buffer_base );
- return -1;
- }
-
- AddMD5( &ctx, buffer, file_size );
-
- DVDCloseFile( dvd_file );
- free( buffer_base );
- nr_of_files++;
+ ssize_t ifo_size = 0;
+ int ret = DiscIDAddFile( dvd, title, DVD_READ_INFO_FILE, &ifo_size, 0, &ctx );
+ if( ret == -1 ) {
+ Log1(dvd, "DVDDiscId, IFO of title set %d unreadable, using its backup",
+ title );
+ ret = DiscIDAddFile( dvd, title, DVD_READ_INFO_BACKUP_FILE, NULL,
+ ifo_size, &ctx );
+ if( ret == 0 )
+ ret = -1; /* no backup either */
}
+ if( ret < 0 )
+ return -1;
+ if( ret > 0 )
+ nr_of_files++;
}
EndMD5( &ctx );
if(!nr_of_files)
=====================================
src/dvdread/dvd_reader.h
=====================================
@@ -336,6 +336,9 @@ DVDREAD_API ssize_t DVDFileSize( dvd_file_t * );
* Get a unique 128 bit disc ID.
* This is the MD5 sum of VIDEO_TS.IFO and the VTS_0?_0.IFO files
* in title order (those that exist).
+ * An IFO file that exists but cannot be read is replaced by its BUP file,
+ * which is meant to hold the same bytes, provided both have the same size.
+ * If neither can be read, there is no ID.
* If you need a 'text' representation of the id, print it as a
* hexadecimal number, using lowercase letters, discid[0] first.
* I.e. the same format as the command-line 'md5sum' program uses.
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/commit/159e42811b1016a1d30be8304bc0617f244ce16a
--
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/commit/159e42811b1016a1d30be8304bc0617f244ce16a
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