Package: wxhexeditor
Version: 0.24+repack-1
Severity: normal
Tags: patch

Dear Maintainer,

Using the (immensely useful) comparison feature in wxHexEditor, I
noticed some bytes are being "missed" by the comparison engine: they are
not marked as differing even though they actually are.

Here is a minimal working example with two files of 12 bytes:

       Int |           0            1            2
      Byte |  0  1  2  3   4  5  6  7   8  9 10 11
-----------+--------------------------------------
test_file0 | 00 00 00 00  00 00 00 00  00 00 00 00
test_file1 | 00 00 00 11  00 00 00 00  22 33 00 00

Differing bytes at offsets 3 and 9 are detected successfully, but not
the one at offset 8.

This appears to be due to the comparison engine switching back and forth
between integer comparison (for increased performance) and byte comparison.
This process involves a pointer which is increased either by increments
of 1 (when comparing bytes) or sizeof(int) (when comparing integers). In
some situations like the one above, it may happen that the coarse
increase can cause the pointer to skip a byte.

A patch is attached with a quick fix for this problem: a small check is
added to ensure that coarse increase of the pointer is disabled if
pointer value is not a multiple of sizeof(int).

Thanks,
Arnaud Meyer.

-- System Information:
Debian Release: bullseye/sid
  APT prefers testing
  APT policy: (800, 'testing'), (500, 'unstable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 5.3.0-3-amd64 (SMP w/8 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), 
LANGUAGE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages wxhexeditor depends on:
ii  libc6                 2.30-2
ii  libdisasm0            0.23-6+b1
ii  libgcc-s1 [libgcc1]   10-20200324-1
ii  libgcc1               1:9.2.1-25
ii  libgomp1              10-20200324-1
ii  libmhash2             0.9.9.9-8
ii  libstdc++6            10-20200324-1
ii  libwxbase3.0-0v5      3.0.4+dfsg-15
ii  libwxgtk3.0-gtk3-0v5  3.0.4+dfsg-15

wxhexeditor recommends no packages.

wxhexeditor suggests no packages.

-- no debconf information
Fixes a bug that causes some bytes to be skipped when comparing two files.

This bug happens because the comparison engine switches from integer (for 
performance) to byte (for accuracy) comparison whenever a difference is 
detected. When switching back to integer comparison, an offset of sizeof(int) 
is applied to the pointer. Under some configurations, this can cause at least 
one byte to be missed by the comparison engine.

This quick fix ensures that applying an offset of sizeof(int) to the pointer is 
performed only when said pointer position is a multiple of sizeof(int).
--- a/src/HexDialogs.cpp
+++ b/src/HexDialogs.cpp
@@ -2347,7 +2347,7 @@
                                        //Here we made the comparison on 
INTEGER for speedup
                                        if( 
bfr_int1[i/sizeof(int)]==bfr_int2[i/sizeof(int)]  ){
                                                //bytes are eq, goto check next 
integer
-                                               if( !diff ){
+                                               if( !diff && ((i % sizeof(int)) 
== 0) ){
                                                        i+=sizeof(int);
                                                        continue;
                                                        }

Reply via email to