Fix TXTH dynamic chunks in some cases

This commit is contained in:
bnnm 2023-07-08 10:53:12 +02:00
parent fc7848bfd3
commit 204d1f560f
2 changed files with 13 additions and 4 deletions

View File

@ -142,6 +142,8 @@ typedef struct {
int chunk_start_set;
int chunk_size_set;
int chunk_count_set;
int chunk_bsize_set;
int chunk_dsize_set;
uint32_t base_offset;
uint32_t is_offset_absolute;
@ -827,7 +829,8 @@ static void set_body_chunk(txth_header* txth) {
//todo maybe should only be done once, or have some count to retrigger to simplify?
if (!txth->chunk_start_set || !txth->chunk_size_set || !txth->chunk_count_set)
return;
if (txth->chunk_size == 0 && !(txth->chunk_bsize_offset || txth->chunk_dsize_offset))
if (txth->chunk_size == 0 && !(txth->chunk_bsize_set || txth->chunk_dsize_set))
return;
if (txth->chunk_start > txth->data_size || txth->chunk_count == 0)
return;
@ -853,6 +856,8 @@ static void set_body_chunk(txth_header* txth) {
cfg.chunk_bsize_offset = txth->chunk_bsize_offset;
cfg.chunk_dsize_offset = txth->chunk_dsize_offset;
cfg.chunk_be = txth->chunk_big_endian;
cfg.chunk_bsize_set = txth->chunk_bsize_set;
cfg.chunk_dsize_set = txth->chunk_dsize_set;
cfg.chunk_start = txth->chunk_start;
cfg.chunk_size = txth->chunk_size;
@ -1473,10 +1478,12 @@ static int parse_keyval(STREAMFILE* sf_, txth_header* txth, const char* key, cha
else if (is_string(key,"chunk_size_offset")) {
if (!parse_num(txth->sf_head,txth,val, &txth->chunk_bsize_offset)) goto fail;
txth->chunk_size_set = 1;
txth->chunk_bsize_set = 1;
}
else if (is_string(key,"chunk_data_size_offset")) {
if (!parse_num(txth->sf_head,txth,val, &txth->chunk_dsize_offset)) goto fail;
txth->chunk_size_set = 1;
txth->chunk_dsize_set = 1;
}
else if (is_string(key,"chunk_endianness")) {
if (!parse_endianness(txth, val, &txth->chunk_big_endian, NULL)) goto fail;

View File

@ -17,6 +17,8 @@ typedef struct {
uint32_t chunk_bsize_offset;
uint32_t chunk_dsize_offset;
int chunk_be;
int chunk_bsize_set;
int chunk_dsize_set;
} txth_io_config_data;
typedef struct {
@ -72,15 +74,15 @@ static size_t txth_io_read(STREAMFILE* sf, uint8_t* dest, off_t offset, size_t l
}
/* chunk size reader (overwrites the above) */
if (data->cfg.chunk_header_size && (data->cfg.chunk_bsize_offset || data->cfg.chunk_dsize_offset)) {
if (data->cfg.chunk_header_size && (data->cfg.chunk_bsize_set || data->cfg.chunk_dsize_set)) {
read_u32_t read_u32 = data->cfg.chunk_be ? read_u32be : read_u32le;
data->block_size = 0;
data->data_size = 0;
if (data->cfg.chunk_bsize_offset)
if (data->cfg.chunk_bsize_set)
data->block_size = read_u32(data->physical_offset + data->cfg.chunk_bsize_offset, sf);
if (data->cfg.chunk_dsize_offset)
if (data->cfg.chunk_dsize_set)
data->data_size = read_u32(data->physical_offset + data->cfg.chunk_dsize_offset, sf);
if (!data->block_size && !data->data_size) { /* bad read? */