|
29 | 29 | /** |
30 | 30 | @brief Read index entry label from buffer pointing at index record data |
31 | 31 | |
32 | | - @param[in,out] output Output string |
| 32 | + @param[in,out] output Output buffer (INDX_LABEL_SIZEMAX + 1 bytes) |
33 | 33 | @param[in,out] buf MOBIBuffer structure, offset pointing at index entry label |
34 | 34 | @param[in] length Number of bytes to be read |
35 | 35 | @param[in] has_ligatures Decode ligatures if true |
36 | | - @return Size of read label |
| 36 | + @return Length of output string (without null terminator), on error buf->error set to MOBI_RET status |
37 | 37 | */ |
38 | 38 | size_t mobi_indx_get_label(unsigned char *output, MOBIBuffer *buf, const size_t length, const size_t has_ligatures) { |
39 | 39 | if (!output) { |
@@ -248,9 +248,9 @@ uint16_t mobi_ordt_lookup(const MOBIOrdt *ordt, const uint16_t offset) { |
248 | 248 | |
249 | 249 | @param[in] ordt MOBIOrdt structure (ORDT data and metadata) |
250 | 250 | @param[in,out] buf MOBIBuffer structure with input string |
251 | | - @param[in,out] output Output buffer (INDX_LABEL_SIZEMAX bytes) |
| 251 | + @param[in,out] output Output buffer (INDX_LABEL_SIZEMAX + 1 bytes) |
252 | 252 | @param[in] length Length of input string contained in buf |
253 | | - @return Number of bytes read |
| 253 | + @return Length of output string (without null terminator) |
254 | 254 | */ |
255 | 255 | size_t mobi_getstring_ordt(const MOBIOrdt *ordt, MOBIBuffer *buf, unsigned char *output, size_t length) { |
256 | 256 | size_t i = 0; |
@@ -362,12 +362,16 @@ static MOBI_RET mobi_parse_index_entry(MOBIIndx *indx, const MOBIIdxt idxt, cons |
362 | 362 | debug_print("Label length too long: %zu\n", label_length); |
363 | 363 | return MOBI_DATA_CORRUPT; |
364 | 364 | } |
365 | | - char text[INDX_LABEL_SIZEMAX]; |
| 365 | + char text[INDX_LABEL_SIZEMAX + 1]; |
366 | 366 | /* FIXME: what is ORDT1 for? */ |
367 | 367 | if (ordt->ordt2) { |
368 | 368 | label_length = mobi_getstring_ordt(ordt, buf, (unsigned char*) text, label_length); |
369 | 369 | } else { |
370 | 370 | label_length = mobi_indx_get_label((unsigned char*) text, buf, label_length, indx->ligt_entries_count); |
| 371 | + if (buf->error != MOBI_SUCCESS) { |
| 372 | + debug_print("Buffer error reading label: %d\n", buf->error); |
| 373 | + return MOBI_DATA_CORRUPT; |
| 374 | + } |
371 | 375 | } |
372 | 376 | indx->entries[entry_number].label = malloc(label_length + 1); |
373 | 377 | if (indx->entries[entry_number].label == NULL) { |
|
0 commit comments