[libdvdnav-devel] [Git][videolan/libdvdread][master] 2 commits: dvd_reader: compute the DVDReadBytes() buffer size in size_t

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Wed Dec 2 10:05:50 UTC 2026



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


Commits:
1dc61295 by sepro at 2026-12-02T09:04:56+01:00
dvd_reader: compute the DVDReadBytes() buffer size in size_t

The block count numsec was an unsigned int, so the buffer size
numsec * DVD_VIDEO_LB_LEN was computed in 32 bits. Where size_t is
64 bits, a byte_size of 4 GiB or more makes it wrap, a small buffer is
allocated, and the block read writes past it, up to the end of the IFO
file, or of the disc image when the file is not cached.

Make numsec a size_t.

- - - - -
c499e7fb by sepro at 2026-12-02T09:04:56+01:00
ifo_read: free a partly read PGC command table only in ifoFree_PGC()

When reading the commands of a PGC failed, ifoRead_PGC_COMMAND_TBL()
freed the commands it had read so far but kept the pointers in the
table. ifoRead_FP_PGC() then frees the PGC with ifoFree_PGC(), which
freed the same commands a second time.

Leave the cleanup to ifoFree_PGC(), as ifoRead_PGC() already does for
everything else it reads. ifoRead_PGCIT_internal() freed a PGC that
failed to read with free() and leaked what had been read of it. Free
it with ifoFree_PGC() too.

- - - - -


2 changed files:

- src/dvd_reader.c
- src/ifo_read.c


Changes:

=====================================
src/dvd_reader.c
=====================================
@@ -1980,7 +1980,8 @@ ssize_t DVDReadBytes( dvd_file_t *dvd_file, void *data, size_t byte_size )
   dvd_reader_t *ctx = dvd_file->ctx;
   dvd_reader_device_t *dvd = ctx->rd;
   unsigned char *secbuf_base, *secbuf;
-  unsigned int numsec, seek_sector, seek_byte;
+  unsigned int seek_sector, seek_byte;
+  size_t numsec;
   int ret;
 
   /* Check arguments. */


=====================================
src/ifo_read.c
=====================================
@@ -2073,46 +2073,26 @@ static int ifoRead_PGC_COMMAND_TBL(ifo_handle_t *ifofile,
     if(!cmd_tbl->pre_cmds)
       return 0;
 
-    if(!(DVDReadBytes(ifop->file, cmd_tbl->pre_cmds, pre_cmds_size))) {
-      free(cmd_tbl->pre_cmds);
+    if(!(DVDReadBytes(ifop->file, cmd_tbl->pre_cmds, pre_cmds_size)))
       return 0;
-    }
   }
 
   if(cmd_tbl->nr_of_post != 0) {
     unsigned int post_cmds_size = cmd_tbl->nr_of_post * COMMAND_DATA_SIZE;
     cmd_tbl->post_cmds = malloc(post_cmds_size);
-    if(!cmd_tbl->post_cmds) {
-      if(cmd_tbl->pre_cmds)
-        free(cmd_tbl->pre_cmds);
+    if(!cmd_tbl->post_cmds)
       return 0;
-    }
-    if(!(DVDReadBytes(ifop->file, cmd_tbl->post_cmds, post_cmds_size))) {
-      if(cmd_tbl->pre_cmds)
-        free(cmd_tbl->pre_cmds);
-      free(cmd_tbl->post_cmds);
+    if(!(DVDReadBytes(ifop->file, cmd_tbl->post_cmds, post_cmds_size)))
       return 0;
-    }
   }
 
   if(cmd_tbl->nr_of_cell != 0) {
     unsigned int cell_cmds_size = cmd_tbl->nr_of_cell * COMMAND_DATA_SIZE;
     cmd_tbl->cell_cmds = malloc(cell_cmds_size);
-    if(!cmd_tbl->cell_cmds) {
-      if(cmd_tbl->pre_cmds)
-        free(cmd_tbl->pre_cmds);
-      if(cmd_tbl->post_cmds)
-        free(cmd_tbl->post_cmds);
+    if(!cmd_tbl->cell_cmds)
       return 0;
-    }
-    if(!(DVDReadBytes(ifop->file, cmd_tbl->cell_cmds, cell_cmds_size))) {
-      if(cmd_tbl->pre_cmds)
-        free(cmd_tbl->pre_cmds);
-      if(cmd_tbl->post_cmds)
-        free(cmd_tbl->post_cmds);
-      free(cmd_tbl->cell_cmds);
+    if(!(DVDReadBytes(ifop->file, cmd_tbl->cell_cmds, cell_cmds_size)))
       return 0;
-    }
   }
 
   /*
@@ -3289,7 +3269,7 @@ static int ifoRead_PGCIT_internal(ifo_handle_t *ifofile, pgcit_t *pgcit,
                     offset + pgcit->pgci_srp[i].pgc_start_byte)) {
       Log0(ifop->ctx, "Unable to read invalid PCG");
       //E-One releases provide bogus PGC, ie: out of bound start_byte
-      free(pgcit->pgci_srp[i].pgc);
+      ifoFree_PGC(pgcit->pgci_srp[i].pgc);
       pgcit->pgci_srp[i].pgc = NULL;
     }
   }



View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/f4a1107290387b8fba3f201f0cb35b393e23c98f...c499e7fb77d289d1b8fd20fcb0e85faf935edb99

-- 
View it on GitLab: https://code.videolan.org/videolan/libdvdread/-/compare/f4a1107290387b8fba3f201f0cb35b393e23c98f...c499e7fb77d289d1b8fd20fcb0e85faf935edb99
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