@@ -209,21 +209,6 @@ pub unsafe extern "C" fn scan_lha_lzh(ctx: *mut cli_ctx) -> cl_error_t {
209
209
// Get the file header.
210
210
let header = decoder. header ( ) ;
211
211
212
- // Verify the CRC check. This is important because LHA/LZH does not have particularly identifiable magic bytes.
213
- match decoder. crc_check ( ) {
214
- Ok ( crc) => {
215
- // CRC is valid. Very likely it is indeed an LHA/LZH archive.
216
- debug ! ( "CRC check passed. Very likely this is an LHA or LZH archive. CRC: {crc}" ) ;
217
- }
218
- Err ( err) => {
219
- // Error checking CRC.
220
- // Use debug-level because may not actually be an LHA/LZH archive.
221
- // LHA/LZH does not have particularly identifiable magic bytes.
222
- debug ! ( "An error occurred when checking the CRC of this LHA or LZH archive: {err}" ) ;
223
- // break;
224
- }
225
- }
226
-
227
212
let filepath = header. parse_pathname ( ) ;
228
213
let filename = filepath. to_string_lossy ( ) ;
229
214
if header. is_directory ( ) {
@@ -254,11 +239,31 @@ pub unsafe extern "C" fn scan_lha_lzh(ctx: *mut cli_ctx) -> cl_error_t {
254
239
debug ! ( "err: unsupported compression method" ) ;
255
240
} else {
256
241
// Read the file into a buffer.
257
- let mut file_data = Vec :: < u8 > :: new ( ) ;
242
+ let mut file_data: Vec < u8 > = Vec :: < u8 > :: new ( ) ;
258
243
259
244
match decoder. read_to_end ( & mut file_data) {
260
245
Ok ( bytes_read) => {
261
246
if bytes_read > 0 {
247
+ debug ! (
248
+ "Read {bytes_read} bytes from file {filename} in the LHA archive."
249
+ ) ;
250
+
251
+ // Verify the CRC check *after* reading the file.
252
+ match decoder. crc_check ( ) {
253
+ Ok ( crc) => {
254
+ // CRC is valid. Very likely this is an LHA or LZH archive.
255
+ debug ! ( "CRC check passed. Very likely this is an LHA or LZH archive. CRC: {crc}" ) ;
256
+ }
257
+ Err ( err) => {
258
+ // Error checking CRC.
259
+ debug ! ( "An error occurred when checking the CRC of this LHA or LZH archive: {err}" ) ;
260
+
261
+ // Allow the scan to continue even with a CRC error, for now.
262
+ // break;
263
+ }
264
+ }
265
+
266
+ // Scan the file.
262
267
let ret =
263
268
magic_scan ( ctx, & file_data, Some ( filename. to_string ( ) ) ) ;
264
269
if ret != cl_error_t_CL_SUCCESS {
0 commit comments