Fix warnings in ID3v2Frame
This commit is contained in:
parent
3d3bc94e39
commit
e93a7c53b3
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <limits>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -997,20 +998,23 @@ void Id3v2Frame::makeEncodingAndData(
|
||||||
if (!data) {
|
if (!data) {
|
||||||
dataSize = 0;
|
dataSize = 0;
|
||||||
}
|
}
|
||||||
|
if (dataSize > numeric_limits<uint32>::max() - 5) {
|
||||||
|
throw InvalidDataException();
|
||||||
|
}
|
||||||
char *bufferDataAddress;
|
char *bufferDataAddress;
|
||||||
switch (encoding) {
|
switch (encoding) {
|
||||||
case TagTextEncoding::Latin1:
|
case TagTextEncoding::Latin1:
|
||||||
case TagTextEncoding::Utf8:
|
case TagTextEncoding::Utf8:
|
||||||
case TagTextEncoding::Unspecified: // assumption
|
case TagTextEncoding::Unspecified: // assumption
|
||||||
// allocate buffer
|
// allocate buffer
|
||||||
buffer = make_unique<char[]>(bufferSize = 1 + dataSize + 1);
|
buffer = make_unique<char[]>(bufferSize = static_cast<uint32>(1 + dataSize + 1));
|
||||||
buffer[0] = static_cast<char>(makeTextEncodingByte(encoding)); // set text encoding byte
|
buffer[0] = static_cast<char>(makeTextEncodingByte(encoding)); // set text encoding byte
|
||||||
bufferDataAddress = buffer.get() + 1;
|
bufferDataAddress = buffer.get() + 1;
|
||||||
break;
|
break;
|
||||||
case TagTextEncoding::Utf16LittleEndian:
|
case TagTextEncoding::Utf16LittleEndian:
|
||||||
case TagTextEncoding::Utf16BigEndian:
|
case TagTextEncoding::Utf16BigEndian:
|
||||||
// allocate buffer
|
// allocate buffer
|
||||||
buffer = make_unique<char[]>(bufferSize = 1 + 2 + dataSize + 2);
|
buffer = make_unique<char[]>(bufferSize = static_cast<uint32>(1 + 2 + dataSize + 2));
|
||||||
buffer[0] = static_cast<char>(makeTextEncodingByte(encoding)); // set text encoding byte
|
buffer[0] = static_cast<char>(makeTextEncodingByte(encoding)); // set text encoding byte
|
||||||
ConversionUtilities::LE::getBytes(
|
ConversionUtilities::LE::getBytes(
|
||||||
encoding == TagTextEncoding::Utf16LittleEndian ? static_cast<uint16>(0xFEFF) : static_cast<uint16>(0xFFFE), buffer.get() + 1);
|
encoding == TagTextEncoding::Utf16LittleEndian ? static_cast<uint16>(0xFEFF) : static_cast<uint16>(0xFFFE), buffer.get() + 1);
|
||||||
|
@ -1063,15 +1067,21 @@ void Id3v2Frame::makeLegacyPicture(unique_ptr<char[]> &buffer, uint32 &bufferSiz
|
||||||
convertedDescription = convertUtf8ToUtf16LE(picture.description().data(), descriptionSize);
|
convertedDescription = convertUtf8ToUtf16LE(picture.description().data(), descriptionSize);
|
||||||
descriptionSize = convertedDescription.second;
|
descriptionSize = convertedDescription.second;
|
||||||
}
|
}
|
||||||
|
|
||||||
// calculate needed buffer size and create buffer
|
// calculate needed buffer size and create buffer
|
||||||
const uint32 dataSize = picture.dataSize();
|
// note: encoding byte + image format + picture type byte + description size + 1 or 2 null bytes (depends on encoding) + data size
|
||||||
buffer = make_unique<char[]>(bufferSize = 1 + 3 + 1 + descriptionSize
|
const auto requiredBufferSize = 1 + 3 + 1 + descriptionSize
|
||||||
+ (descriptionEncoding == TagTextEncoding::Utf16BigEndian || descriptionEncoding == TagTextEncoding::Utf16LittleEndian ? 4 : 1)
|
+ (descriptionEncoding == TagTextEncoding::Utf16BigEndian || descriptionEncoding == TagTextEncoding::Utf16LittleEndian ? 4 : 1)
|
||||||
+ dataSize);
|
+ picture.dataSize();
|
||||||
// note: encoding byte + image format + picture type byte + description size + 1 or 2 null bytes (depends on encoding) + data size
|
if (requiredBufferSize > numeric_limits<uint32>::max()) {
|
||||||
|
throw InvalidDataException();
|
||||||
|
}
|
||||||
|
buffer = make_unique<char[]>(bufferSize = static_cast<uint32>(requiredBufferSize));
|
||||||
char *offset = buffer.get();
|
char *offset = buffer.get();
|
||||||
|
|
||||||
// write encoding byte
|
// write encoding byte
|
||||||
*offset = static_cast<char>(makeTextEncodingByte(descriptionEncoding));
|
*offset = static_cast<char>(makeTextEncodingByte(descriptionEncoding));
|
||||||
|
|
||||||
// write mime type
|
// write mime type
|
||||||
const char *imageFormat;
|
const char *imageFormat;
|
||||||
if (picture.mimeType() == "image/jpeg") {
|
if (picture.mimeType() == "image/jpeg") {
|
||||||
|
@ -1086,8 +1096,10 @@ void Id3v2Frame::makeLegacyPicture(unique_ptr<char[]> &buffer, uint32 &bufferSiz
|
||||||
imageFormat = "UND";
|
imageFormat = "UND";
|
||||||
}
|
}
|
||||||
strncpy(++offset, imageFormat, 3);
|
strncpy(++offset, imageFormat, 3);
|
||||||
|
|
||||||
// write picture type
|
// write picture type
|
||||||
*(offset += 3) = static_cast<char>(typeInfo);
|
*(offset += 3) = static_cast<char>(typeInfo);
|
||||||
|
|
||||||
// write description
|
// write description
|
||||||
offset += makeBom(offset + 1, descriptionEncoding);
|
offset += makeBom(offset + 1, descriptionEncoding);
|
||||||
if (convertedDescription.first) {
|
if (convertedDescription.first) {
|
||||||
|
@ -1099,6 +1111,7 @@ void Id3v2Frame::makeLegacyPicture(unique_ptr<char[]> &buffer, uint32 &bufferSiz
|
||||||
if (descriptionEncoding == TagTextEncoding::Utf16BigEndian || descriptionEncoding == TagTextEncoding::Utf16LittleEndian) {
|
if (descriptionEncoding == TagTextEncoding::Utf16BigEndian || descriptionEncoding == TagTextEncoding::Utf16LittleEndian) {
|
||||||
*(++offset) = 0x00;
|
*(++offset) = 0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
// write actual data
|
// write actual data
|
||||||
copy(picture.dataPointer(), picture.dataPointer() + picture.dataSize(), ++offset);
|
copy(picture.dataPointer(), picture.dataPointer() + picture.dataSize(), ++offset);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue