Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

FS#13299: Handle MP3 files with more than 128K of headers before audio data

Encountered a file with ~600K of ID3v1 headers.

Optimize the potential overhead by minimizing reverse seeks.

Change-Id: I972dbf1af1c36659f19c7ab4eed0b9149c642880

+15 -12
+15 -12
lib/rbcodec/metadata/mp3data.c
··· 260 260 * seek to this byte position and check if there is another 261 261 * valid MPEG frame header of the same type. */ 262 262 struct mp3info info; 263 - 263 + 264 264 /* Gather frame size from given header and seek to next 265 265 * frame header. */ 266 - mp3headerinfo(&info, header); 266 + if (!mp3headerinfo(&info, header)) continue; 267 267 lseek(fd, info.frame_size-4, SEEK_CUR); 268 - 268 + 269 269 /* Read possible next frame header and seek back to last frame 270 270 * headers byte position. */ 271 271 reference_header = 0; 272 272 read_uint32be_mp3data(fd, &reference_header); 273 - // 274 - lseek(fd, -info.frame_size, SEEK_CUR); 275 - 276 - /* If the current header is of the same type as the previous 277 - * header we are finished. */ 278 - if (headers_have_same_type(header, reference_header)) 273 + 274 + /* If the current header is of the same type as the previous 275 + * header we are finished. Rewind to frame data start. */ 276 + if (headers_have_same_type(header, reference_header)) { 277 + lseek(fd, -info.frame_size, SEEK_CUR); 279 278 break; 279 + } 280 + /* Otherwise keep going. Rewind to to start of "next" frame. */ 281 + lseek(fd, -4, SEEK_CUR); 282 + pos += info.frame_size - 4; 280 283 } 281 284 } 282 - 285 + 283 286 } while (true); 284 287 285 288 *offset = pos - 4; ··· 511 514 { 512 515 long tmp; 513 516 unsigned long header = 0; 514 - 515 - header = __find_next_frame(fd, &tmp, 0x20000, 0, fileread, single_header); 517 + 518 + header = __find_next_frame(fd, &tmp, 0x100000, 0, fileread, single_header); 516 519 if(header == 0) 517 520 return -1; 518 521