Guard against writes of too big sectors.

This commit is contained in:
2025-12-30 20:14:05 +00:00
parent 7f0dea2755
commit b7e0f60673
2 changed files with 9 additions and 0 deletions

View File

@@ -67,6 +67,7 @@
#define AARUF_ERROR_TAPE_FILE_NOT_FOUND (-28) ///< Requested tape file number not present in image.
#define AARUF_ERROR_TAPE_PARTITION_NOT_FOUND (-29) ///< Requested tape partition not present in image.
#define AARUF_ERROR_METADATA_NOT_PRESENT (-30) ///< Requested metadata not present in image.
#define AARUF_ERROR_INVALID_SECTOR_LENGTH (-31) ///< Sector length is too big.
/** @} */
/** \name Non-fatal sector status codes (non-negative)

View File

@@ -147,6 +147,14 @@ AARU_EXPORT int32_t AARU_CALL aaruf_write_sector(void *context, uint64_t sector_
return AARUF_ERROR_SECTOR_OUT_OF_BOUNDS;
}
if(length > USHRT_MAX)
{
FATAL("Sector length too large");
TRACE("Exiting aaruf_write_sector() = AARUF_ERROR_INVALID_SECTOR_LENGTH");
return AARUF_ERROR_INVALID_SECTOR_LENGTH;
}
if(length > ctx->header.biggestSectorSize) ctx->header.biggestSectorSize = (uint16_t)length;
if(!ctx->rewinded)