Skip to content

Commit 0d788ab

Browse files
committed
maybe fix chmlib crash seen in crash reports
1 parent 0287f0d commit 0d788ab

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ext/CHMLib/chm_lib.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,11 +1125,14 @@ static int64_t _chm_decompress_region(struct chmFile* h, uint8_t* buf, uint64_t
11251125
if (nLen > (h->reset_table.block_len - nOffset))
11261126
nLen = h->reset_table.block_len - nOffset;
11271127

1128-
/* if block is cached, return data from it. */
1129-
if (h->cache_block_indices[nBlock % h->cache_num_blocks] == nBlock &&
1130-
h->cache_blocks[nBlock % h->cache_num_blocks] != NULL) {
1131-
memcpy(buf, h->cache_blocks[nBlock % h->cache_num_blocks] + nOffset, (unsigned int)nLen);
1132-
return nLen;
1128+
/* SumatraPDF: seen in a crash report */
1129+
if (h->cache_num_blocks > 0) {
1130+
/* if block is cached, return data from it. */
1131+
if (h->cache_block_indices[nBlock % h->cache_num_blocks] == nBlock &&
1132+
h->cache_blocks[nBlock % h->cache_num_blocks] != NULL) {
1133+
memcpy(buf, h->cache_blocks[nBlock % h->cache_num_blocks] + nOffset, (unsigned int)nLen);
1134+
return nLen;
1135+
}
11331136
}
11341137

11351138
/* data request not satisfied, so... start up the decompressor machine */

0 commit comments

Comments
 (0)