@@ -1155,6 +1155,21 @@ static int build(const struct optstruct *opts)
1155
1155
free (tarfile );
1156
1156
return -1 ;
1157
1157
}
1158
+
1159
+
1160
+ // Check if the MD5 starts with 00. If it does, we'll return CL_ELAST_ERROR. The caller may try again for better luck.
1161
+ // This is to avoid a bug in hash verification with ClamAV 1.1 -> 1.4. The bug was fixed in 1.5.0.
1162
+ // TODO: Remove this workaround when no one is using those versions.
1163
+ if (pt [0 ] == '0' && pt [1 ] == '0' ) {
1164
+ // print out the pt hash
1165
+ mprintf (LOGG_INFO , "The tar.gz MD5 starts with 00, which will fail to verify in ClamAV 1.1 -> 1.4: %s\n" , pt );
1166
+ fclose (fh );
1167
+ unlink (tarfile );
1168
+ free (tarfile );
1169
+ free (pt );
1170
+ return CL_ELAST_ERROR ;
1171
+ }
1172
+
1158
1173
rewind (fh );
1159
1174
sprintf (header + strlen (header ), "%s:" , pt );
1160
1175
free (pt );
@@ -3768,9 +3783,15 @@ int main(int argc, char **argv)
3768
3783
ret = asciinorm (opts );
3769
3784
else if (optget (opts , "utf16-decode" )-> enabled )
3770
3785
ret = utf16decode (opts );
3771
- else if (optget (opts , "build" )-> enabled )
3786
+ else if (optget (opts , "build" )-> enabled ) {
3772
3787
ret = build (opts );
3773
- else if (optget (opts , "unpack" )-> enabled )
3788
+ if (ret == CL_ELAST_ERROR ) {
3789
+ // build() returns CL_ELAST_ERROR the hash starts with 00. This will fail to verify with ClamAV 1.1 -> 1.4.
3790
+ // Retry the build again to get new hashes.
3791
+ mprintf (LOGG_WARNING , "Retrying the build for a chance at a better hash.\n" );
3792
+ ret = build (opts );
3793
+ }
3794
+ } else if (optget (opts , "unpack" )-> enabled )
3774
3795
ret = unpack (opts );
3775
3796
else if (optget (opts , "unpack-current" )-> enabled )
3776
3797
ret = unpack (opts );
0 commit comments