Fossil SCM
Fix a potential unsigned integer overflow in blob_uncompress(), reported by Özgün Kültekin.
Commit
525a1376172f1459c28f4b14c4c4cc614c369ca428f97008bc509416a7060072
Parent
6b3e4f8fbd38377…
1 file changed
+3
-1
+3
-1
| --- src/blob.c | ||
| +++ src/blob.c | ||
| @@ -1488,10 +1488,12 @@ | ||
| 1488 | 1488 | /* |
| 1489 | 1489 | ** Uncompress blob pIn and store the result in pOut. It is ok for pIn and |
| 1490 | 1490 | ** pOut to be the same blob. |
| 1491 | 1491 | ** |
| 1492 | 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. | |
| 1493 | 1495 | */ |
| 1494 | 1496 | int blob_uncompress(Blob *pIn, Blob *pOut){ |
| 1495 | 1497 | unsigned int nOut; |
| 1496 | 1498 | unsigned char *inBuf; |
| 1497 | 1499 | unsigned int nIn = blob_size(pIn); |
| @@ -1502,11 +1504,11 @@ | ||
| 1502 | 1504 | return 0; |
| 1503 | 1505 | } |
| 1504 | 1506 | inBuf = (unsigned char*)blob_buffer(pIn); |
| 1505 | 1507 | nOut = (inBuf[0]<<24) + (inBuf[1]<<16) + (inBuf[2]<<8) + inBuf[3]; |
| 1506 | 1508 | blob_zero(&temp); |
| 1507 | - blob_resize(&temp, nOut+1); | |
| 1509 | + blob_resize(&temp, (u64)nOut+1); | |
| 1508 | 1510 | nOut2 = (long int)nOut; |
| 1509 | 1511 | rc = uncompress((unsigned char*)blob_buffer(&temp), &nOut2, |
| 1510 | 1512 | &inBuf[4], nIn - 4); |
| 1511 | 1513 | if( rc!=Z_OK ){ |
| 1512 | 1514 | blob_reset(&temp); |
| 1513 | 1515 |
| --- 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 |