From 69605b6c61bde5b6b1bfdefaf7ca66802b0c5158 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Wed, 5 Jul 2017 22:23:21 -0700 Subject: [PATCH] isomp4: atomsrecovery: handle common and large atom headers Do not assume all files are large files. Check and use the short or extended atom size field only if needed. https://bugzilla.gnome.org/show_bug.cgi?id=784258 --- gst/isomp4/atomsrecovery.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/gst/isomp4/atomsrecovery.c b/gst/isomp4/atomsrecovery.c index 24bc31c6e7..5462713e71 100644 --- a/gst/isomp4/atomsrecovery.c +++ b/gst/isomp4/atomsrecovery.c @@ -1030,8 +1030,8 @@ moov_recov_write_file (MoovRecovFile * moovrf, MdatRecovFile * mdatrf, /* add chunks offsets */ for (i = 0; i < moovrf->num_traks; i++) { TrakRecovData *trak = &(moovrf->traks_rd[i]); - /* 16 for the mdat header */ - gint64 offset = moov_size + ftell (outf) + 16; + /* 8 or 16 for the mdat header */ + gint64 offset = moov_size + ftell (outf) + mdatrf->mdat_header_size; atom_stco64_chunks_set_offset (&trak->stbl.stco64, offset); } @@ -1135,10 +1135,21 @@ moov_recov_write_file (MoovRecovFile * moovrf, MdatRecovFile * mdatrf, /* write the mdat */ /* write the header first */ - GST_WRITE_UINT32_BE (auxdata, 1); - GST_WRITE_UINT32_LE (auxdata + 4, FOURCC_mdat); - GST_WRITE_UINT64_BE (auxdata + 8, mdatrf->mdat_size); - if (fwrite (auxdata, 1, 16, outf) != 16) { + if (mdatrf->mdat_header_size == 16) { + GST_WRITE_UINT32_BE (auxdata, 1); + GST_WRITE_UINT32_LE (auxdata + 4, FOURCC_mdat); + GST_WRITE_UINT64_BE (auxdata + 8, mdatrf->mdat_size); + } else if (mdatrf->mdat_header_size == 8) { + GST_WRITE_UINT32_BE (auxdata, mdatrf->mdat_size); + GST_WRITE_UINT32_LE (auxdata + 4, FOURCC_mdat); + } else { + GST_ERROR ("Unexpected atom size: %u", mdatrf->mdat_header_size); + g_assert_not_reached (); + goto fail; + } + + if (fwrite (auxdata, 1, mdatrf->mdat_header_size, + outf) != mdatrf->mdat_header_size) { ATOMS_RECOV_OUTPUT_WRITE_ERROR (err); goto fail; }