Changed error codes again
This commit is contained in:
parent
f27830e07a
commit
36520dee7e
@ -18,7 +18,7 @@ uint8_t parse_caff_header(uint8_t *data, uint64_t data_len, uint64_t *num_anim)
|
||||
caff_header_t *header_info = (caff_header_t *) data;
|
||||
|
||||
if (header_info->magic != 0x46464143) {
|
||||
return CAFF_PARSE_BAD_MAGIC;
|
||||
return CAFF_PARSE_HEADER_BAD_MAGIC;
|
||||
}
|
||||
|
||||
if (header_info->header_size != 20) {
|
||||
@ -44,21 +44,21 @@ uint8_t validate_caff_credits(uint8_t *data, uint64_t data_len) {
|
||||
credits_header_t *header_info = (credits_header_t *) data;
|
||||
|
||||
if (header_info->month > 12 || header_info->month == 0) {
|
||||
return CAFF_PARSE_BAD_DATE;
|
||||
return CAFF_PARSE_CREDITS_BAD_DATE;
|
||||
}
|
||||
|
||||
uint8_t month_lengths[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
|
||||
|
||||
if (header_info->day > month_lengths[header_info->month - 1] || header_info->day == 0) {
|
||||
return CAFF_PARSE_BAD_DATE;
|
||||
return CAFF_PARSE_CREDITS_BAD_DATE;
|
||||
}
|
||||
|
||||
if (header_info->hour > 23) {
|
||||
return CAFF_PARSE_BAD_DATE;
|
||||
return CAFF_PARSE_CREDITS_BAD_DATE;
|
||||
}
|
||||
|
||||
if (header_info->minute > 60) {
|
||||
return CAFF_PARSE_BAD_DATE;
|
||||
return CAFF_PARSE_CREDITS_BAD_DATE;
|
||||
}
|
||||
|
||||
uint64_t calculated_len = header_info->creator_len + sizeof(credits_header_t);
|
||||
@ -80,7 +80,7 @@ uint8_t validate_caff_animation(uint8_t *data, uint64_t data_len) {
|
||||
|
||||
|
||||
if (header_info->duration == 0) {
|
||||
return CAFF_PARSE_NO_DURATION;
|
||||
return CAFF_PARSE_ANIMATION_NO_DURATION;
|
||||
}
|
||||
|
||||
// NOTE: Ciff validation is solved in the CIFF tools
|
||||
@ -126,7 +126,7 @@ uint8_t validate_caff_file(uint8_t *data, uint64_t data_len) {
|
||||
|
||||
if ((frame_counter == 0 && frame_header->id != CAFF_FRAME_HEADER) ||
|
||||
(frame_counter > 0 && frame_header->id == CAFF_FRAME_HEADER)) {
|
||||
return CAFF_PARSE_HEADER_ERROR;
|
||||
return CAFF_PARSE_HEADER_PLACE_ERROR;
|
||||
}
|
||||
|
||||
uint8_t result;
|
||||
|
@ -10,12 +10,12 @@
|
||||
#define CAFF_PARSE_ERROR_PREFIX 0x10
|
||||
#define CAFF_PARSE_LENGTH_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x01)
|
||||
#define CAFF_PARSE_BAD_FRAME (CAFF_PARSE_ERROR_PREFIX + 0x02)
|
||||
#define CAFF_PARSE_HEADER_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x03)
|
||||
#define CAFF_PARSE_HEADER_PLACE_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x03)
|
||||
#define CAFF_PARSE_ANIMATION_COUNT_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x04)
|
||||
#define CAFF_PARSE_NO_CREDITS_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x05)
|
||||
#define CAFF_PARSE_BAD_MAGIC (CAFF_PARSE_ERROR_PREFIX + 0x06)
|
||||
#define CAFF_PARSE_BAD_DATE (CAFF_PARSE_ERROR_PREFIX + 0x07)
|
||||
#define CAFF_PARSE_NO_DURATION (CAFF_PARSE_ERROR_PREFIX + 0x08)
|
||||
#define CAFF_PARSE_HEADER_BAD_MAGIC (CAFF_PARSE_ERROR_PREFIX + 0x06)
|
||||
#define CAFF_PARSE_CREDITS_BAD_DATE (CAFF_PARSE_ERROR_PREFIX + 0x07)
|
||||
#define CAFF_PARSE_ANIMATION_NO_DURATION (CAFF_PARSE_ERROR_PREFIX + 0x08)
|
||||
#define CAFF_PARSE_UNKNOWN_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x09)
|
||||
|
||||
#define CAFF_PARSE_SUCCESS 0x00
|
||||
|
@ -9,7 +9,7 @@ uint8_t validate_ciff(const uint8_t* data, uint64_t data_len) {
|
||||
|
||||
// Read out the static part of the header (If we have at least header bytes)
|
||||
if (data_len < sizeof(ciff_static_header_t)) {
|
||||
return CIFF_PARSE_HEADER_TOO_SHORT;
|
||||
return CIFF_PARSE_LENGTH_ERROR;
|
||||
}
|
||||
|
||||
// This is just a pointer with different type information
|
||||
@ -23,28 +23,32 @@ uint8_t validate_ciff(const uint8_t* data, uint64_t data_len) {
|
||||
|
||||
// Check if the fields in the header seems valid (none of the size fields larger than the whole file)
|
||||
if ((header_info->header_size > data_len) || (header_info->content_size > data_len)) {
|
||||
return CIFF_PARSE_HEADER_LENGTHS_INCORRECT;
|
||||
return CIFF_PARSE_LENGTH_ERROR;
|
||||
}
|
||||
|
||||
if ((header_info->header_size+header_info->content_size) > data_len) {
|
||||
return CIFF_PARSE_HEADER_LENGTHS_INCORRECT;
|
||||
return CIFF_PARSE_LENGTH_ERROR;
|
||||
}
|
||||
|
||||
if (header_info->width == 0 || header_info->height == 0) {
|
||||
return CIFF_PARSE_HEADER_DIMENSIONS_INCORRECT;
|
||||
}
|
||||
|
||||
// Pre-Calculate some variables and check against those as well
|
||||
uint64_t calculated_pixeldata_length_by_header = header_info->width * header_info->height * 3;
|
||||
if (data_len < calculated_pixeldata_length_by_header) {
|
||||
// The number of pixels defined in the header is larger than the while file
|
||||
return CIFF_PARSE_HEADER_DIMENSIONS_INCORRECT;
|
||||
// The number of pixels defined in the header is larger than the whole file
|
||||
return CIFF_PARSE_LENGTH_ERROR;
|
||||
}
|
||||
|
||||
if (calculated_pixeldata_length_by_header != header_info->content_size) {
|
||||
return CIFF_PARSE_HEADER_DIMENSIONS_INCORRECT;
|
||||
return CIFF_PARSE_LENGTH_ERROR;
|
||||
}
|
||||
|
||||
uint64_t calculated_total_length_by_header = calculated_pixeldata_length_by_header + header_info->header_size;
|
||||
if (calculated_total_length_by_header != data_len) {
|
||||
// The header + pixel data is not equals the length of the file
|
||||
return CIFF_PARSE_HEADER_LENGTHS_INCORRECT;
|
||||
return CIFF_PARSE_LENGTH_ERROR;
|
||||
}
|
||||
|
||||
// Do some other checks to validate the header
|
||||
|
@ -8,11 +8,10 @@
|
||||
#include <stdint.h>
|
||||
|
||||
#define CIFF_PARSE_ERROR_PREFIX 0x20
|
||||
#define CIFF_PARSE_HEADER_LENGTHS_INCORRECT (CIFF_PARSE_ERROR_PREFIX + 0x01)
|
||||
#define CIFF_PARSE_LENGTH_ERROR (CIFF_PARSE_ERROR_PREFIX + 0x01)
|
||||
#define CIFF_PARSE_HEADER_DIMENSIONS_INCORRECT (CIFF_PARSE_ERROR_PREFIX + 0x02)
|
||||
#define CIFF_PARSE_HEADER_TOO_SHORT (CIFF_PARSE_ERROR_PREFIX + 0x03)
|
||||
#define CIFF_PARSE_HEADER_BAD_MAGIC (CIFF_PARSE_ERROR_PREFIX + 0x04)
|
||||
#define CIFF_PARSE_UNKNOWN_ERROR (CIFF_PARSE_ERROR_PREFIX + 0x05)
|
||||
#define CIFF_PARSE_HEADER_BAD_MAGIC (CIFF_PARSE_ERROR_PREFIX + 0x03)
|
||||
#define CIFF_PARSE_UNKNOWN_ERROR (CIFF_PARSE_ERROR_PREFIX + 0x04)
|
||||
|
||||
#define CIFF_PARSE_SUCCESS 0x00
|
||||
|
||||
|
@ -12,8 +12,8 @@
|
||||
#define USAGE_ERROR_PREFIX 0x50
|
||||
#define USAGE_ERROR_WRONG_PARAMETERS (USAGE_ERROR_PREFIX + 0x01)
|
||||
|
||||
#define OTHER_ERROR_PREFIX 0x60
|
||||
#define OTHER_FLIP_COULD_NOT_ALLOCATE (OTHER_ERROR_PREFIX + 0x01)
|
||||
// Warning: This is defined outside the pixeldata_utils.h (because this event could happen here only)
|
||||
#define IMAGE_FLIP_COULD_NOT_ALLOCATE (IMAGE_FLIP_ERROR_PREFIX + 0x02)
|
||||
|
||||
// Mivel az egyszerűség kedvéért az egész fájlt memóriába olvassuk, jobb ha limitáljuk a méretét
|
||||
#define CAFF_MAX_SIZE 536870912 // 512MB
|
||||
@ -58,7 +58,7 @@ uint8_t perform_extraction(mm_ctx context, const char *infile, const char *outfi
|
||||
uint8_t *flipped_pixel_data = (uint8_t *) magic_malloc(context, pixel_data_len);
|
||||
|
||||
if (flipped_pixel_data == NULL) {
|
||||
return OTHER_FLIP_COULD_NOT_ALLOCATE;
|
||||
return IMAGE_FLIP_COULD_NOT_ALLOCATE;
|
||||
}
|
||||
|
||||
result = flip_image(pixel_data, flipped_pixel_data, pixel_data_len, width, height);
|
||||
|
Loading…
Reference in New Issue
Block a user