--- apps/codecs/aac.c (revision 30012) +++ apps/codecs/aac.c (working copy) @@ -231,9 +231,23 @@ /* Gather number of samples for the decoded frame. */ framelength = (frame_info.samples >> 1) - lead_trim; - if (i == demux_res.num_sample_byte_sizes - 1) + if (i == demux_res.num_sample_byte_sizes - 1 && framelength > 0) { + /* Currently limited to at most one frame of tail_trim. + * Seems to be enough. + */ + if (ci->id3->tail_trim == 0 + && (frame_info.samples >> 1)) + { + /* Subtract lead_trim just in case we decode a file with + * only one audio frame with actual data. + */ + framelength = - lead_trim; + } + else + { framelength -= ci->id3->tail_trim; + } } if (framelength > 0)