[libbluray-devel] fix handling of short reads

hpi1 git at videolan.org
Wed Apr 15 11:27:35 CEST 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Wed Apr 15 12:27:13 2015 +0300| [c981241464550f0b55cfee17cef6a5914a609b9e] | committer: hpi1

fix handling of short reads

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=c981241464550f0b55cfee17cef6a5914a609b9e
---

 src/libbluray/bluray.c |   33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index 5fb20a6..d60ad55 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -627,6 +627,25 @@ static int _validate_unit(BLURAY *bd, BD_STREAM *st, uint8_t *buf)
     return 1;
 }
 
+static int _skip_unit(BLURAY *bd, BD_STREAM *st)
+{
+    const size_t len = 6144;
+
+    /* skip broken unit */
+    st->clip_block_pos += len;
+    st->clip_pos += len;
+
+    _queue_event(bd, BD_EVENT_READ_ERROR, 0);
+
+    /* seek to next unit start */
+    if (file_seek(st->fp, st->clip_block_pos, SEEK_SET) < 0) {
+        BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Unable to seek clip %s!\n", st->clip->name);
+        return -1;
+    }
+
+    return 0;
+}
+
 static int _read_block(BLURAY *bd, BD_STREAM *st, uint8_t *buf)
 {
     const size_t len = 6144;
@@ -642,6 +661,7 @@ static int _read_block(BLURAY *bd, BD_STREAM *st, uint8_t *buf)
 
                 if (read_len != len) {
                     BD_DEBUG(DBG_STREAM | DBG_CRIT, "Read %d bytes at %"PRIu64" ; requested %d !\n", (int)read_len, st->clip_block_pos, (int)len);
+                    return _skip_unit(bd, st);
                 }
                 st->clip_block_pos += len;
 
@@ -672,18 +692,7 @@ static int _read_block(BLURAY *bd, BD_STREAM *st, uint8_t *buf)
 
             BD_DEBUG(DBG_STREAM | DBG_CRIT, "Read unit at %"PRIu64" failed !\n", st->clip_block_pos);
 
-            _queue_event(bd, BD_EVENT_READ_ERROR, 0);
-
-            /* skip broken unit */
-            st->clip_block_pos += len;
-            st->clip_pos += len;
-
-            if (file_seek(st->fp, st->clip_block_pos, SEEK_SET) < 0) {
-                BD_DEBUG(DBG_BLURAY | DBG_CRIT, "Unable to seek clip %s!\n", st->clip->name);
-                return -1;
-            }
-
-            return 0;
+            return _skip_unit(bd, st);
         }
 
         /* This is caused by truncated .m2ts file or invalid clip length.



More information about the libbluray-devel mailing list