mirror of
https://github.com/ksherlock/profuse.git
synced 2024-05-28 22:41:39 +00:00
DC42 validation, fix infinite loop with validation.
git-svn-id: https://profuse.googlecode.com/svn/branches/profuse_interim@377 aa027e90-d47c-11dd-86d7-074df07e0730
This commit is contained in:
parent
5ab8fd3d87
commit
77e5994908
|
@ -170,41 +170,38 @@ BlockDevicePointer DiskCopy42Image::Create(const char *name, size_t blocks, cons
|
||||||
return MAKE_SHARED(DiskCopy42Image, file);
|
return MAKE_SHARED(DiskCopy42Image, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiskCopy42Image::Validate(MappedFile *file)
|
bool DiskCopy42Image::Validate(MappedFile *file, const std::nothrow_t &)
|
||||||
{
|
{
|
||||||
#undef __METHOD__
|
#undef __METHOD__
|
||||||
#define __METHOD__ "DiskCopy42Image::Validate"
|
#define __METHOD__ "DiskCopy42Image::Validate"
|
||||||
|
|
||||||
|
|
||||||
size_t bytes = 0;
|
size_t bytes = 0;
|
||||||
size_t size = file->length();
|
size_t size = file->length();
|
||||||
const void *data = file->address();
|
const void *data = file->address();
|
||||||
bool ok = false;
|
|
||||||
uint32_t checksum = 0;
|
uint32_t checksum = 0;
|
||||||
|
|
||||||
do {
|
if (size < oUserData)
|
||||||
if (size < oUserData) break;
|
return false;
|
||||||
|
|
||||||
// name must be < 64
|
|
||||||
if (Read8(data, 0) > 63) break;
|
|
||||||
|
|
||||||
if (Read16(data, oPrivate) != 0x100)
|
|
||||||
break;
|
|
||||||
|
|
||||||
// bytes, not blocks.
|
|
||||||
bytes = Read32(data, oDataSize);
|
|
||||||
|
|
||||||
if (bytes % 512) break;
|
|
||||||
|
|
||||||
if (size < oUserData + bytes) break;
|
|
||||||
|
|
||||||
// todo -- checksum.
|
|
||||||
checksum = Read32(data, oDataChecksum);
|
|
||||||
|
|
||||||
ok = true;
|
|
||||||
} while (false);
|
|
||||||
|
|
||||||
if (!ok)
|
// name must be < 64
|
||||||
throw Exception(__METHOD__ ": Invalid file format.");
|
if (Read8(data, 0) > 63)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (Read16(data, oPrivate) != 0x100)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// bytes, not blocks.
|
||||||
|
bytes = Read32(data, oDataSize);
|
||||||
|
|
||||||
|
if (bytes % 512)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (size < oUserData + bytes)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// todo -- checksum.
|
||||||
|
checksum = Read32(data, oDataChecksum);
|
||||||
|
|
||||||
uint32_t cs = Checksum(oUserData + (uint8_t *)data, bytes);
|
uint32_t cs = Checksum(oUserData + (uint8_t *)data, bytes);
|
||||||
|
|
||||||
|
@ -212,7 +209,21 @@ void DiskCopy42Image::Validate(MappedFile *file)
|
||||||
{
|
{
|
||||||
fprintf(stderr, __METHOD__ ": Warning: checksum invalid.\n");
|
fprintf(stderr, __METHOD__ ": Warning: checksum invalid.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DiskCopy42Image::Validate(MappedFile *file)
|
||||||
|
{
|
||||||
|
#undef __METHOD__
|
||||||
|
#define __METHOD__ "DiskCopy42Image::Validate"
|
||||||
|
|
||||||
|
|
||||||
|
if (!Validate(file, std::nothrow))
|
||||||
|
throw Exception(__METHOD__ ": Invalid file format.");
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiskCopy42Image::write(unsigned block, const void *bp)
|
void DiskCopy42Image::write(unsigned block, const void *bp)
|
||||||
|
|
|
@ -19,6 +19,11 @@ public:
|
||||||
|
|
||||||
static uint32_t Checksum(void *data, size_t size);
|
static uint32_t Checksum(void *data, size_t size);
|
||||||
|
|
||||||
|
static bool Validate(MappedFile *, const std::nothrow_t &);
|
||||||
|
static bool Validate(MappedFile *);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual void write(unsigned block, const void *bp);
|
virtual void write(unsigned block, const void *bp);
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +34,6 @@ private:
|
||||||
DiskCopy42Image();
|
DiskCopy42Image();
|
||||||
|
|
||||||
DiskCopy42Image(MappedFile *);
|
DiskCopy42Image(MappedFile *);
|
||||||
static void Validate(MappedFile *);
|
|
||||||
bool _changed;
|
bool _changed;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -149,7 +149,7 @@ bool ProDOSOrderDiskImage::Validate(MappedFile *f)
|
||||||
|
|
||||||
if (!f || !f->isValid()) throw Exception(__METHOD__ ": File not set.");
|
if (!f || !f->isValid()) throw Exception(__METHOD__ ": File not set.");
|
||||||
|
|
||||||
if (!Validate(f))
|
if (!Validate(f, std::nothrow))
|
||||||
throw Exception(__METHOD__ ": Invalid file format.");
|
throw Exception(__METHOD__ ": Invalid file format.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -221,7 +221,7 @@ bool DOSOrderDiskImage::Validate(MappedFile *f)
|
||||||
if (!f || !f->isValid()) throw Exception(__METHOD__ ": File not set.");
|
if (!f || !f->isValid()) throw Exception(__METHOD__ ": File not set.");
|
||||||
|
|
||||||
|
|
||||||
if (!Validate(f))
|
if (!Validate(f, std::nothrow))
|
||||||
throw Exception(__METHOD__ ": Invalid file format.");
|
throw Exception(__METHOD__ ": Invalid file format.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -226,7 +226,7 @@ bool SDKImage::Validate(MappedFile * f)
|
||||||
#undef __METHOD__
|
#undef __METHOD__
|
||||||
#define __METHOD__ "SDKImage::Validate"
|
#define __METHOD__ "SDKImage::Validate"
|
||||||
|
|
||||||
if (!Validate(f))
|
if (!Validate(f, std::nothrow))
|
||||||
throw Exception(__METHOD__ ": Invalid file format.");
|
throw Exception(__METHOD__ ": Invalid file format.");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user