diff --git a/include/aaruformat/errors.h b/include/aaruformat/errors.h index 6e6b35f..bf9d6a0 100644 --- a/include/aaruformat/errors.h +++ b/include/aaruformat/errors.h @@ -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) diff --git a/src/write.c b/src/write.c index 3d5a757..9e4837f 100644 --- a/src/write.c +++ b/src/write.c @@ -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)