Fossil SCM

Fix a potential unsigned integer overflow in blob_uncompress(), reported by Özgün Kültekin.

drh 2026-11-20 00:26 UTC trunk
Commit 525a1376172f1459c28f4b14c4c4cc614c369ca428f97008bc509416a7060072
1 file changed +3 -1
+3 -1
--- src/blob.c
+++ src/blob.c
@@ -1488,10 +1488,12 @@
14881488
/*
14891489
** Uncompress blob pIn and store the result in pOut. It is ok for pIn and
14901490
** pOut to be the same blob.
14911491
**
14921492
** pOut must be either uninitialized or the same as pIn.
1493
+**
1494
+** Return the number of errors encountered, which means return 0 on success.
14931495
*/
14941496
int blob_uncompress(Blob *pIn, Blob *pOut){
14951497
unsigned int nOut;
14961498
unsigned char *inBuf;
14971499
unsigned int nIn = blob_size(pIn);
@@ -1502,11 +1504,11 @@
15021504
return 0;
15031505
}
15041506
inBuf = (unsigned char*)blob_buffer(pIn);
15051507
nOut = (inBuf[0]<<24) + (inBuf[1]<<16) + (inBuf[2]<<8) + inBuf[3];
15061508
blob_zero(&temp);
1507
- blob_resize(&temp, nOut+1);
1509
+ blob_resize(&temp, (u64)nOut+1);
15081510
nOut2 = (long int)nOut;
15091511
rc = uncompress((unsigned char*)blob_buffer(&temp), &nOut2,
15101512
&inBuf[4], nIn - 4);
15111513
if( rc!=Z_OK ){
15121514
blob_reset(&temp);
15131515
--- src/blob.c
+++ src/blob.c
@@ -1488,10 +1488,12 @@
1488 /*
1489 ** Uncompress blob pIn and store the result in pOut. It is ok for pIn and
1490 ** pOut to be the same blob.
1491 **
1492 ** pOut must be either uninitialized or the same as pIn.
 
 
1493 */
1494 int blob_uncompress(Blob *pIn, Blob *pOut){
1495 unsigned int nOut;
1496 unsigned char *inBuf;
1497 unsigned int nIn = blob_size(pIn);
@@ -1502,11 +1504,11 @@
1502 return 0;
1503 }
1504 inBuf = (unsigned char*)blob_buffer(pIn);
1505 nOut = (inBuf[0]<<24) + (inBuf[1]<<16) + (inBuf[2]<<8) + inBuf[3];
1506 blob_zero(&temp);
1507 blob_resize(&temp, nOut+1);
1508 nOut2 = (long int)nOut;
1509 rc = uncompress((unsigned char*)blob_buffer(&temp), &nOut2,
1510 &inBuf[4], nIn - 4);
1511 if( rc!=Z_OK ){
1512 blob_reset(&temp);
1513
--- src/blob.c
+++ src/blob.c
@@ -1488,10 +1488,12 @@
1488 /*
1489 ** Uncompress blob pIn and store the result in pOut. It is ok for pIn and
1490 ** pOut to be the same blob.
1491 **
1492 ** pOut must be either uninitialized or the same as pIn.
1493 **
1494 ** Return the number of errors encountered, which means return 0 on success.
1495 */
1496 int blob_uncompress(Blob *pIn, Blob *pOut){
1497 unsigned int nOut;
1498 unsigned char *inBuf;
1499 unsigned int nIn = blob_size(pIn);
@@ -1502,11 +1504,11 @@
1504 return 0;
1505 }
1506 inBuf = (unsigned char*)blob_buffer(pIn);
1507 nOut = (inBuf[0]<<24) + (inBuf[1]<<16) + (inBuf[2]<<8) + inBuf[3];
1508 blob_zero(&temp);
1509 blob_resize(&temp, (u64)nOut+1);
1510 nOut2 = (long int)nOut;
1511 rc = uncompress((unsigned char*)blob_buffer(&temp), &nOut2,
1512 &inBuf[4], nIn - 4);
1513 if( rc!=Z_OK ){
1514 blob_reset(&temp);
1515

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button