comparison tools/lib64gfx.c @ 2122:59bde9a7220d

Add few out of bounds checks.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 27 May 2019 05:59:57 +0300
parents f12ac487954b
children 56d4dc81774b
comparison
equal deleted inserted replaced
2121:f12ac487954b 2122:59bde9a7220d
1315 // Hi-res charmap 1315 // Hi-res charmap
1316 const int x = xc / 8; 1316 const int x = xc / 8;
1317 const int scroffs = scroffsy + x; 1317 const int scroffs = scroffsy + x;
1318 const int xshift = 7 - (xc & 7); 1318 const int xshift = 7 - (xc & 7);
1319 const int chr = src->screen[0].data[scroffs]; 1319 const int chr = src->screen[0].data[scroffs];
1320 1320 const size_t chrOffs = (chr * C64_CHR_SIZE) + yb;
1321 if ((src->charData[0].data[chr * C64_CHR_SIZE + yb] >> xshift) & 1) 1321
1322 if (chrOffs >= src->charData[0].size)
1323 {
1324 return dmError(DMERR_INVALID_DATA,
1325 "Character map index #%d out of bounds for char ROM data.\n",
1326 chr);
1327 }
1328
1329 if ((src->charData[0].data[chrOffs] >> xshift) & 1)
1322 *dp++ = src->color[0].data[scroffs]; 1330 *dp++ = src->color[0].data[scroffs];
1323 else 1331 else
1324 *dp++ = src->bgcolor; 1332 *dp++ = src->bgcolor;
1325 } 1333 }
1326 else 1334 else
1329 // Hi-res ECM charmap 1337 // Hi-res ECM charmap
1330 const int x = xc / 8; 1338 const int x = xc / 8;
1331 const int scroffs = scroffsy + x; 1339 const int scroffs = scroffsy + x;
1332 const int xshift = 7 - (xc & 7); 1340 const int xshift = 7 - (xc & 7);
1333 const int chr = src->screen[0].data[scroffs]; 1341 const int chr = src->screen[0].data[scroffs];
1334 1342 const size_t chrOffs = ((chr & 0x3f) * C64_CHR_SIZE) + yb;
1335 if ((src->charData[0].data[(chr & 0x3f) * C64_CHR_SIZE + yb] >> xshift) & 1) 1343
1344 if (chrOffs >= src->charData[0].size)
1345 {
1346 return dmError(DMERR_INVALID_DATA,
1347 "Character map index #%d out of bounds for char ROM data.\n",
1348 chr);
1349 }
1350
1351 if ((src->charData[0].data[chrOffs] >> xshift) & 1)
1336 *dp++ = src->color[0].data[scroffs] & 15; 1352 *dp++ = src->color[0].data[scroffs] & 15;
1337 else 1353 else
1338 switch ((chr >> 6) & 3) 1354 switch ((chr >> 6) & 3)
1339 { 1355 {
1340 case 0: *dp++ = src->bgcolor; break; 1356 case 0: *dp++ = src->bgcolor; break;
1349 // Multicolor charmap 1365 // Multicolor charmap
1350 const int x = xc / 4; 1366 const int x = xc / 4;
1351 const int scroffs = scroffsy + x; 1367 const int scroffs = scroffsy + x;
1352 const int chr = src->screen[0].data[scroffs]; 1368 const int chr = src->screen[0].data[scroffs];
1353 const int col = src->color[0].data[scroffs]; 1369 const int col = src->color[0].data[scroffs];
1370 const size_t chrOffs = (chr * C64_CHR_SIZE) + yb;
1371
1372 if (chrOffs >= src->charData[0].size)
1373 {
1374 return dmError(DMERR_INVALID_DATA,
1375 "Character map index #%d out of bounds for char ROM data.\n",
1376 chr);
1377 }
1354 1378
1355 if (col & 8) 1379 if (col & 8)
1356 { 1380 {
1357 const int xshift = 6 - ((xc * 2) & 6); 1381 const int xshift = 6 - ((xc * 2) & 6);
1358 switch ((src->charData[0].data[chr * C64_CHR_SIZE + yb] >> xshift) & 3) 1382 switch ((src->charData[0].data[chrOffs] >> xshift) & 3)
1359 { 1383 {
1360 case 0: *dp++ = src->bgcolor; break; 1384 case 0: *dp++ = src->bgcolor; break;
1361 case 1: *dp++ = src->d022; break; 1385 case 1: *dp++ = src->d022; break;
1362 case 2: *dp++ = src->d023; break; 1386 case 2: *dp++ = src->d023; break;
1363 case 3: *dp++ = col & 15; 1387 case 3: *dp++ = col & 15;
1364 } 1388 }
1365 } 1389 }
1366 else 1390 else
1367 { 1391 {
1368 const int xshift = 7 - (xc & 7); 1392 const int xshift = 7 - (xc & 7);
1369 if ((src->charData[0].data[chr * C64_CHR_SIZE + yb] >> xshift) & 1) 1393 if ((src->charData[0].data[chrOffs] >> xshift) & 1)
1370 *dp++ = col & 7; 1394 *dp++ = col & 7;
1371 else 1395 else
1372 *dp++ = src->bgcolor; 1396 *dp++ = src->bgcolor;
1373 } 1397 }
1374 } 1398 }