Index: apps/buffering.c =================================================================== --- apps/buffering.c (revision 23172) +++ apps/buffering.c (working copy) @@ -430,18 +430,19 @@ /* Some part of the struct + data would wrap, maybe ok */ size_t correction = 0; /* If the overlap lands inside the memory_handle */ - if ((unsigned)overlap > data_size) { + /* !can_wrap has priority */ + if (!can_wrap) { + /* The overlap falls in the struct and data area and must all be + * backed out. This may become conditional if ever we move + * data that is allowed to wrap (ie audio) */ + correction = overlap; + } else if ((unsigned)overlap > data_size) { /* Correct the position and real delta to prevent the struct from * wrapping, this guarantees an aligned delta, I think */ correction = overlap - data_size; - } else if (!can_wrap) { - /* Otherwise the overlap falls in the data area and must all be - * backed out. This may become conditional if ever we move - * data that is allowed to wrap (ie audio) */ - correction = overlap; + } /* Align correction to four bytes, up */ correction = (correction+3) & ~3; - } if (correction) { if (final_delta < correction + sizeof(struct memory_handle)) { /* Delta cannot end up less than the size of the struct */ @@ -776,7 +777,9 @@ delta = handle_distance - h->available; /* The value of delta might change for alignment reasons */ - if (!move_handle(&h, &delta, h->available, h->type==TYPE_CODEC)) + /* do not wrap handle (CODEC, ID3) */ + + if (!move_handle(&h, &delta, h->available, false)) return; size_t olddata = h->data; @@ -938,8 +941,11 @@ return ERR_FILE_ERROR; size_t size = filesize(fd); - bool can_wrap = type==TYPE_PACKET_AUDIO || type==TYPE_CODEC; + /* only packet audio is wrappable */ + + bool can_wrap = type==TYPE_PACKET_AUDIO; + size_t adjusted_offset = offset; if (adjusted_offset > size) adjusted_offset = 0;