I read on with ++ id3v2 tags mp3 file. At some point, an APIC tag appears, whose frame size is too large to be stored in memory. The program crashes, how to get around this? I read tags in a loop like this:

char input[4]; file.read(input, 4); //название тэга cout << input << " "; delete[] input; input = new char[4]; file.read(input, 4); //длина тэга unsigned int length = (int)input[0]*2097152 + (int)input[1]*16384 + (int)input[2]*128 + (int)input[0]; delete[] input; input = new char[2]; file.read(input, 2); //флаги delete[] input; input = new char[length]; // здесь ошибка из-за очень большого length (больше размера файла - 4Гб) file.read(input, length); cout << input << endl; 

The error appears not only on APIC, but also on PRIV in another file for a similar reason.

  • one
    You don't need to dynamically allocate memory to read the title. To read the length, it was possible to simply declare a variable, and read 4 bytes into it using a pointer: unsigned int length; file.read(&length, 4); unsigned int length; file.read(&length, 4); (we assume that int is 32-bit, but it’s better to explicitly use a variable with a size of 32 bits ( uint32_t )). Well, just in case, check if the length field is exactly there, and not something else. - insolor
  • @insolor thanks, but how to check that there is exactly the length field? It is impossible to send uint32_t * to read - the compiler swears at the invalid conversion to char *. - Ilya Koldunov
  • one
    check the docks one more time by format) - insolor

0