Permalink
Browse files

Skip unhandled elements by reading and discarding their contents rath…

…er than

seeking past them.  This means that non-seekable streams are more easily
supported and don't need to special-case seeking forward.

Also fix a warning in test.c found by Clang's static analysis.
  • Loading branch information...
1 parent 1414dc9 commit fd84c148ed9ebe41366f0d13aa46056dd5b7c57b @kinetiknz kinetiknz committed Jun 16, 2010
Showing with 28 additions and 9 deletions.
  1. +1 −3 TODO
  2. +26 −5 src/nestegg.c
  3. +1 −1 test/test.c
View
@@ -1,6 +1,4 @@
-- Document when read, seek, tell callbacks are used. seek used to skip
- unknown, for non-seekable streams this can be implemented as simple
- read-forward.
+- Document when read, seek, tell callbacks are used.
- Add an automated testsuite.
- Test (and fix, if necessary) support for unknown sizes.
- Test (and fix, if necessary) support for large files.
View
@@ -494,6 +494,25 @@ io_seek(nestegg_io * io, int64_t offset, int whence)
return io->seek(offset, whence, io->userdata);
}
+static int
+io_read_skip(nestegg_io * io, size_t length)
+{
+ size_t get;
+ unsigned char buf[8192];
+ int r = 1;
+
+ while (length > 0) {
+ get = length < sizeof(buf) ? length : sizeof(buf);
+ r = io_read(io, buf, get);
+ if (r != 1) {
+ break;
+ }
+ length -= get;
+ }
+
+ return r;
+}
+
static int64_t
io_tell(nestegg_io * io)
{
@@ -969,8 +988,10 @@ parse(nestegg * ctx, struct ebml_element_desc * top_level)
if (element->flags & DESC_FLAG_OFFSET) {
data_offset = (int64_t *) (ctx->ancestor->data + element->data_offset);
*data_offset = io_tell(ctx->io);
- if (*data_offset < 0)
- return -1;
+ if (*data_offset < 0) {
+ r = -1;
+ break;
+ }
}
if (element->type == TYPE_MASTER) {
@@ -1000,9 +1021,9 @@ parse(nestegg * ctx, struct ebml_element_desc * top_level)
if (id != ID_VOID && id != ID_CRC32)
ctx->log(ctx, NESTEGG_LOG_DEBUG, "unknown element %llx", id);
- r = io_seek(ctx->io, size, NESTEGG_SEEK_CUR);
- if (r != 0)
- return -1;
+ r = io_read_skip(ctx->io, size);
+ if (r != 1)
+ break;
}
}
View
@@ -217,7 +217,7 @@ main(int argc, char * argv[])
}
}
- while ((r = nestegg_read_packet(ctx, &pkt)) > 0) {
+ while (nestegg_read_packet(ctx, &pkt) > 0) {
nestegg_packet_track(pkt, &pkt_track);
nestegg_packet_count(pkt, &pkt_cnt);
nestegg_packet_tstamp(pkt, &pkt_tstamp);

0 comments on commit fd84c14

Please sign in to comment.