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.
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