Fossil SCM

Avoid a potential 32-bit integer overflow when doing a diff on large files with large differences.

drh 2023-07-28 16:18 trunk
Commit 5882e9e87861c7c07aad78304fccfbe8114e7c2de0ff660aa393f3b22b89ae73
1 file changed +3 -1
+3 -1
--- src/diff.c
+++ src/diff.c
@@ -2093,11 +2093,13 @@
20932093
}
20942094
20952095
/* For large alignments, try to use alternative algorithms that are
20962096
** faster than the O(N*N) Wagner edit distance.
20972097
*/
2098
- if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){
2098
+ if( (i64)nLeft*(i64)nRight>DIFF_ALIGN_MX
2099
+ && (pCfg->diffFlags & DIFF_SLOW_SBS)==0
2100
+ ){
20992101
if( (pCfg->diffFlags & DIFF_IGNORE_ALLWS)==0 ){
21002102
unsigned char *aRes;
21012103
aRes = diffBlockAlignmentIgnoreSpace(
21022104
aLeft, nLeft,aRight, nRight,pCfg,pNResult);
21032105
if( aRes ) return aRes;
21042106
--- src/diff.c
+++ src/diff.c
@@ -2093,11 +2093,13 @@
2093 }
2094
2095 /* For large alignments, try to use alternative algorithms that are
2096 ** faster than the O(N*N) Wagner edit distance.
2097 */
2098 if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){
 
 
2099 if( (pCfg->diffFlags & DIFF_IGNORE_ALLWS)==0 ){
2100 unsigned char *aRes;
2101 aRes = diffBlockAlignmentIgnoreSpace(
2102 aLeft, nLeft,aRight, nRight,pCfg,pNResult);
2103 if( aRes ) return aRes;
2104
--- src/diff.c
+++ src/diff.c
@@ -2093,11 +2093,13 @@
2093 }
2094
2095 /* For large alignments, try to use alternative algorithms that are
2096 ** faster than the O(N*N) Wagner edit distance.
2097 */
2098 if( (i64)nLeft*(i64)nRight>DIFF_ALIGN_MX
2099 && (pCfg->diffFlags & DIFF_SLOW_SBS)==0
2100 ){
2101 if( (pCfg->diffFlags & DIFF_IGNORE_ALLWS)==0 ){
2102 unsigned char *aRes;
2103 aRes = diffBlockAlignmentIgnoreSpace(
2104 aLeft, nLeft,aRight, nRight,pCfg,pNResult);
2105 if( aRes ) return aRes;
2106

Keyboard Shortcuts

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