Commit 16576d6f authored by Leslie Zhai's avatar Leslie Zhai

Revert from{2,4}Byte.

Hi Thomas:
Please help me! I have no idea why num_wr_speed_des (numDesc) might
be wrong? and how to make it correct if bigger than (32 - 8) / 4,
and where the *magic numbers* about 32 and 8 come from.

Testcase by Matthias Schwarzott!

CCMAIL: scdbackup@gmx.net
CCBUG: 382941
parent d2679715
......@@ -3226,21 +3226,23 @@ QList<int> K3b::Device::Device::determineSupportedWriteSpeeds() const
}
bool K3b::Device::Device::getSupportedWriteSpeedsVia2A( QList<int>& list, MediaType mediaType ) const
bool K3b::Device::Device::getSupportedWriteSpeedsVia2A(QList<int>& list, MediaType mediaType) const
{
UByteArray data;
if( modeSense( data, 0x2A ) ) {
if (modeSense(data, 0x2A)) {
mm_cap_page_2A* mm = (mm_cap_page_2A*)&data[8];
if( data.size() > 32 ) {
// FIXME: why > 32? not bigger than 64?
if (data.size() > 32) {
// we have descriptors
unsigned int numDesc = from2Byte( mm->num_wr_speed_des );
unsigned int numDesc = from2Byte(mm->num_wr_speed_des);
// Some CDs writer returns the number of bytes that contain
// the descriptors rather than the number of descriptors
// Ensure number of descriptors claimed actually fits in the data
// returned by the mode sense command.
if( static_cast<int>( numDesc ) > ((data.size() - 32 - 8) / 4) )
// FIXME: why 32 - 8? not minus 9 or 10?
if (static_cast<int>(numDesc) > ((data.size() - 32 - 8) / 4))
numDesc = (data.size() - 32 - 8) / 4;
cd_wr_speed_performance* wr = (cd_wr_speed_performance*)mm->wr_speed_des;
......@@ -3249,9 +3251,10 @@ bool K3b::Device::Device::getSupportedWriteSpeedsVia2A( QList<int>& list, MediaT
<< ": Number of supported write speeds via 2A: "
<< numDesc << endl;
for( unsigned int i = 0; i < numDesc; ++i ) {
int s = (int)from2Byte( wr[i].wr_speed_supp );
// FIXME: if numDesc is wrong, wr[i] might be out-of-bounds, then
// from2Byte failed to work.
for (unsigned int i = 0; i < numDesc; ++i) {
int s = (int)from2Byte(wr[i].wr_speed_supp);
//
// some DVD writers report CD writing speeds here
// If that is the case we cannot rely on the reported speeds
......
......@@ -214,7 +214,7 @@ void K3b::Device::debugBitfield( unsigned char* data, long len )
quint16 K3b::Device::from2Byte(const unsigned char* d)
{
if (d == NULL || strlen((const char *) d) < 2) {
if (d == NULL) {
qWarning() << "Invalid Byte!";
return 0;
}
......@@ -225,7 +225,7 @@ quint16 K3b::Device::from2Byte(const unsigned char* d)
quint32 K3b::Device::from4Byte(const unsigned char* d)
{
if (d == NULL || strlen((const char *) d) < 4) {
if (d == NULL) {
qWarning() << "Invalid Byte!";
return 0;
}
......
......@@ -24,13 +24,27 @@ DeviceGlobalsTest::DeviceGlobalsTest()
void DeviceGlobalsTest::testFrom2Byte()
{
unsigned char* d = NULL;
QCOMPARE(K3b::Device::from2Byte(d), (quint16)0);
unsigned char buf[1] = { '\0' };
QCOMPARE(K3b::Device::from2Byte(buf), (quint16)0);
QCOMPARE(K3b::Device::from2Byte(d), (quint16)0); // Invalid Byte!
const unsigned char buf0[] = { '\0' };
QCOMPARE(K3b::Device::from2Byte(buf0), (quint16)0);
unsigned const char buf1[] = { 0x00, 0x00 };
QCOMPARE(K3b::Device::from2Byte(buf1), (quint16)0x0000);
unsigned const char buf2[] = { 0x00, 0x70 };
QCOMPARE(K3b::Device::from2Byte(buf2), (quint16)0x0070);
unsigned const char buf3[] = { 0x05, 0x00 };
QCOMPARE(K3b::Device::from2Byte(buf3), (quint16)0x0500);
unsigned const char buf4[] = { 0xF0, 0x03 };
QCOMPARE(K3b::Device::from2Byte(buf4), (quint16)0xF003);
}
void DeviceGlobalsTest::testFrom4Byte()
{
unsigned char d[1] = { '\0' };
QCOMPARE(K3b::Device::from4Byte(d), (quint32)0);
const unsigned char buf0[] = { '\0' };
QCOMPARE(K3b::Device::from4Byte(buf0), (quint32)0);
unsigned const char buf1[] = { 0x00, 0x00, 0x00, 0x00 };
QCOMPARE(K3b::Device::from4Byte(buf1), (quint32)0x00000000);
unsigned const char buf2[] = { 0x00, 0x00, 0x00, 0x01 };
QCOMPARE(K3b::Device::from4Byte(buf2), (quint32)0x00000001);
unsigned const char buf3[] = { 0x12, 0x34, 0x56, 0x78 };
QCOMPARE(K3b::Device::from4Byte(buf3), (quint32)0x12345678);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment