[FFmpeg-devel] Issue with ogg page termination on full last page with even last segment size

Peter Zebühr peter at zebuhr.se
Tue Dec 15 15:35:12 EET 2020


Hello!

I have stumbled on an issue with the ogg page termination in a probably quite rare case.
If the last page ends up full (255 segments) and the last packet that is written is an even multiple of 255 that needs to be terminated with a lacing value of zero that spills over to the next page, then oggenc fails to write a last page that contains the zero lacing value and libogg will fail to detect the end of stream when parsing the produced file. Example:

1. Last page contains 253 segments
2. Packet arrives of size 510 bytes
3. Packet it split into three segments of sizes [255, 255, 0]
4. Page gets the two segments [255, 255] and is full
5. A new page is created containing only the [0] lacing value but no actual data
6. The last page is ignored when completing the stream (because it contains 0 bytes data)

I have a patch that fixes this (attached) in the case that I had, but... one of the fate tests fail (lavf-ogg) and I need some help to reason about what the right thing to do is. 

The reason the test fails is because one extra page is created with my patch. The reason why one extra page is created is because the previous page is completed as it hits the "pref_duration" setting of 1 second (https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/oggenc.c#L261) and then write_packet is called with one more packet of size 0 bytes. The questions I have are:
* Is this a reasonable regression? From the ogg perspective it sounds kind of reasonable that a 0 byte packet would result in a 0 byte segment but not sure why write_packet is even called with a 0 byte packet.
* If this is not a reasonable regression I could either:
   - short circuit handling of a 0 byte packet and make it produce 0 segments in ogg_buffer_data
   OR
   - tweak the logic in the proposed change to write_trailer to make it consider segment_count only if the ongoing page is a continuation of the previous page.
  (OR perhaps it is another bug that a 0 byte packet is written?)


/ Peter

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fix-ogg-page-termination-on-even-last-packets.patch
Type: application/octet-stream
Size: 1309 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20201215/ad1fa16d/attachment.obj>


More information about the ffmpeg-devel mailing list