1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-12-11 15:49:38 +00:00

Support zero-length files; further fix bounds checks.

This commit is contained in:
Thomas Harte 2024-12-02 17:23:50 -05:00
parent 32beafc12d
commit 9fa71231c4
3 changed files with 26 additions and 25 deletions

View File

@ -216,34 +216,36 @@ std::vector<File> Analyser::Static::Commodore::GetFiles(const std::shared_ptr<St
} }
new_file.name = Storage::Data::Commodore::petscii_from_bytes(&new_file.raw_name[0], 16, false); new_file.name = Storage::Data::Commodore::petscii_from_bytes(&new_file.raw_name[0], 16, false);
std::size_t number_of_sectors = const std::size_t number_of_sectors =
size_t(directory[header_pointer + 0x1e]) + size_t(directory[header_pointer + 0x1e]) +
(size_t(directory[header_pointer + 0x1f]) << 8); (size_t(directory[header_pointer + 0x1f]) << 8);
new_file.data.reserve((number_of_sectors - 1) * 254 + 252); if(number_of_sectors) {
new_file.data.reserve((number_of_sectors - 1) * 254 + 252);
bool is_first_sector = true; bool is_first_sector = true;
while(next_track) { while(next_track) {
sector = parser.sector(next_track, next_sector); sector = parser.sector(next_track, next_sector);
if(!sector) break; if(!sector) break;
next_track = sector->data[0]; next_track = sector->data[0];
next_sector = sector->data[1]; next_sector = sector->data[1];
if(is_first_sector) new_file.starting_address = uint16_t(sector->data[2]) | uint16_t(sector->data[3] << 8); if(is_first_sector) new_file.starting_address = uint16_t(sector->data[2]) | uint16_t(sector->data[3] << 8);
if(next_track) if(next_track)
new_file.data.insert( new_file.data.insert(
new_file.data.end(), new_file.data.end(),
sector->data.begin() + (is_first_sector ? 4 : 2), sector->data.begin() + (is_first_sector ? 4 : 2),
sector->data.end() sector->data.end()
); );
else else
new_file.data.insert( new_file.data.insert(
new_file.data.end(), new_file.data.end(),
sector->data.begin() + 2, sector->data.begin() + 2,
sector->data.begin() + next_sector sector->data.begin() + next_sector
); );
is_first_sector = false; is_first_sector = false;
}
} }
if(!next_track) files.push_back(new_file); if(!next_track) files.push_back(new_file);

View File

@ -23,7 +23,7 @@ bool Analyser::Static::Commodore::File::is_basic() {
// ... null-terminated code ... // ... null-terminated code ...
// (with a next line address of 0000 indicating end of program) // (with a next line address of 0000 indicating end of program)
while(1) { while(1) {
if(size_t(line_address - starting_address) >= data.size() - 2) break; if(size_t(line_address - starting_address) + 1 >= data.size()) break;
uint16_t next_line_address = data[line_address - starting_address]; uint16_t next_line_address = data[line_address - starting_address];
next_line_address |= data[line_address - starting_address + 1] << 8; next_line_address |= data[line_address - starting_address + 1] << 8;
@ -33,7 +33,7 @@ bool Analyser::Static::Commodore::File::is_basic() {
} }
if(next_line_address < line_address + 5) break; if(next_line_address < line_address + 5) break;
if(size_t(line_address - starting_address) >= data.size() - 5) break; if(size_t(line_address - starting_address) + 3 >= data.size()) break;
uint16_t next_line_number = data[line_address - starting_address + 2]; uint16_t next_line_number = data[line_address - starting_address + 2];
next_line_number |= data[line_address - starting_address + 3] << 8; next_line_number |= data[line_address - starting_address + 3] << 8;

View File

@ -27,7 +27,6 @@
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES" shouldUseLaunchSchemeArgsEnv = "YES"
enableAddressSanitizer = "YES"
disableMainThreadChecker = "YES" disableMainThreadChecker = "YES"
codeCoverageEnabled = "YES"> codeCoverageEnabled = "YES">
<MacroExpansion> <MacroExpansion>