https://bugs.kde.org/show_bug.cgi?id=475176
Bug ID: 475176 Summary: crash from std::bad_alloc when comparing folders with a huge file and "Full Analysis" File Comparison Mode Classification: Applications Product: kdiff3 Version: 1.10.6 Platform: Slackware OS: Linux Status: REPORTED Severity: normal Priority: NOR Component: application Assignee: reeves...@gmail.com Reporter: erich.public+bugs.kde....@protonmail.com Target Milestone: --- SUMMARY When comparing 2 folders which contain a huge file (>1 GB) and the "Full Analysis" File Comparison Mode option set, kdiff3 will eventually crash (before the initial folder diff comparison is finished, i.e. before the user can interact with the program). When "Binary Comparison" File Comparison Mode option is set, kdiff3 does not crash. STEPS TO REPRODUCE 1. Create 2 folders with a huge file (this will take a LOOONG time; feel free to create the files some other way): $ cat do_test.sh #!/bin/bash mkdir tmp1 mkdir tmp2 for outer in {1..20000} ; do echo "outer=$outer" >> tmp1/tmp.dat echo "outer=$outer" >> tmp2/tmp.dat echo $RANDOM >> tmp1/tmp.dat echo $RANDOM >> tmp2/tmp.dat for _inner in {1..9999} ; do VAL=$RANDOM echo $VAL >> tmp1/tmp.dat echo $VAL >> tmp2/tmp.dat done done for outer in {1..100} ; do for _inner in {1..999} ; do VAL=$RANDOM echo $VAL >> tmp1/"tmp$outer.dat" echo $VAL >> tmp2/"tmp$outer.dat" done done kdiff3 tmp1 tmp2 # EOF $ ls -lh tmp1/tmp.dat -rw-r--r-- 1 erich erich 1.1G Oct 3 08:04 tmp1/tmp.dat $ ls -lh tmp1/tmp1.dat -rw-r--r-- 1 erich erich 5.5K Oct 3 08:04 tmp1/tmp1.dat 2. Use kdiff3 to diff folders tmp1 and tmp2, making sure "Full Analysis" File Comparison Mode option is set (Settings -> Folder -> File Comparison Mode -> Full Analysis). OBSERVED RESULT kdiff3 crashes with the following message at the command line: terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Running under gdb produces the following stack trace: $ gdb kdiff3 GNU gdb (GDB) 11.2 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-slackware-linux". Type "show configuration" for configuration details. For bug reporting instructions, please see: <https://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from kdiff3... (gdb) c The program is not being run. (gdb) run Starting program: /usr/bin/kdiff3 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". [New Thread 0x7ffff204f640 (LWP 81117)] [New Thread 0x7fffebfff640 (LWP 81128)] org.kde.kdiff3: "Diff: A <-> B" org.kde.kdiff3: "Linediff: A <-> B" org.kde.kdiff3: Enter: calcDiff3LineListUsingAB org.kde.kdiff3: Leave: calcDiff3LineListUsingAB [New Thread 0x7fffde7ff640 (LWP 81196)] [New Thread 0x7fffddffe640 (LWP 81197)] [New Thread 0x7fffdd7fd640 (LWP 81198)] [New Thread 0x7fffdcffc640 (LWP 81199)] [New Thread 0x7fffcffff640 (LWP 81200)] [New Thread 0x7fffcf7fe640 (LWP 81201)] [New Thread 0x7fffceffd640 (LWP 81202)] [New Thread 0x7fffce7fc640 (LWP 81203)] [New Thread 0x7fffcdffb640 (LWP 81204)] [New Thread 0x7fffcd7fa640 (LWP 81205)] [New Thread 0x7fffccff9640 (LWP 81206)] [New Thread 0x7fffaffff640 (LWP 81207)] [New Thread 0x7fffaf7fe640 (LWP 81208)] [New Thread 0x7fffaeffd640 (LWP 81209)] [New Thread 0x7fffae7fc640 (LWP 81210)] [New Thread 0x7fffadffb640 (LWP 81211)] [New Thread 0x7fffad7fa640 (LWP 81212)] [New Thread 0x7fffacff9640 (LWP 81213)] [New Thread 0x7fff8ffff640 (LWP 81214)] [New Thread 0x7fff8f7fe640 (LWP 81215)] [New Thread 0x7fff8effd640 (LWP 81216)] [New Thread 0x7fff8e7fc640 (LWP 81217)] [New Thread 0x7fff8dffb640 (LWP 81218)] [New Thread 0x7fff8d7fa640 (LWP 81219)] [New Thread 0x7fff8cff9640 (LWP 81220)] [New Thread 0x7fff6ffff640 (LWP 81221)] [New Thread 0x7fff6f7fe640 (LWP 81222)] [New Thread 0x7fff6effd640 (LWP 81223)] [New Thread 0x7fff6e7fc640 (LWP 81224)] [New Thread 0x7fff6dffb640 (LWP 81225)] [New Thread 0x7fff6d7fa640 (LWP 81226)] [New Thread 0x7fff6cff9640 (LWP 81227)] [New Thread 0x7fff4ffff640 (LWP 81228)] [New Thread 0x7fff4f7fe640 (LWP 81229)] [New Thread 0x7fff4effd640 (LWP 81230)] [Detaching after fork from child process 81239] [Detaching after fork from child process 81241] [Detaching after fork from child process 81243] [Detaching after fork from child process 81244] [Detaching after fork from child process 81246] org.kde.kdiff3.fileAccess: Reading folder: "/home/erich/data/system/pkgs/kdiff3/tmp/tmp1" org.kde.kdiff3.fileAccess: Reading folder: "/home/erich/data/system/pkgs/kdiff3/tmp/tmp2" org.kde.kdiff3: "Loading A: /home/erich/data/system/pkgs/kdiff3/tmp/tmp1/tmp.dat" [Thread 0x7fffcf7fe640 (LWP 81201) exited] [Thread 0x7fff6effd640 (LWP 81223) exited] [Thread 0x7fff6d7fa640 (LWP 81226) exited] [Thread 0x7fffadffb640 (LWP 81211) exited] [Thread 0x7fffacff9640 (LWP 81213) exited] [Thread 0x7fffddffe640 (LWP 81197) exited] [Thread 0x7fff8ffff640 (LWP 81214) exited] [Thread 0x7fff8dffb640 (LWP 81218) exited] [Thread 0x7fffce7fc640 (LWP 81203) exited] [Thread 0x7fff8d7fa640 (LWP 81219) exited] [Thread 0x7fffcffff640 (LWP 81200) exited] [Thread 0x7fff4ffff640 (LWP 81228) exited] [Thread 0x7fff4effd640 (LWP 81230) exited] [Thread 0x7fffaffff640 (LWP 81207) exited] [Thread 0x7fffcd7fa640 (LWP 81205) exited] [Thread 0x7fff8effd640 (LWP 81216) exited] [Thread 0x7fffaeffd640 (LWP 81209) exited] [Thread 0x7fffcdffb640 (LWP 81204) exited] [Thread 0x7fffccff9640 (LWP 81206) exited] [Thread 0x7fffceffd640 (LWP 81202) exited] [Thread 0x7fff8f7fe640 (LWP 81215) exited] [Thread 0x7fff8cff9640 (LWP 81220) exited] [Thread 0x7fffdd7fd640 (LWP 81198) exited] [Thread 0x7fff6f7fe640 (LWP 81222) exited] [Thread 0x7fff6dffb640 (LWP 81225) exited] [Thread 0x7fffaf7fe640 (LWP 81208) exited] [Thread 0x7fffae7fc640 (LWP 81210) exited] [Thread 0x7fff6ffff640 (LWP 81221) exited] [Thread 0x7fff8e7fc640 (LWP 81217) exited] [Thread 0x7fffdcffc640 (LWP 81199) exited] [Thread 0x7fff6cff9640 (LWP 81227) exited] [Thread 0x7fff6e7fc640 (LWP 81224) exited] [Thread 0x7fff4f7fe640 (LWP 81229) exited] [Thread 0x7fffad7fa640 (LWP 81212) exited] terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Thread 1 "kdiff3" received signal SIGABRT, Aborted. 0x00007ffff585c868 in raise () from /lib64/libc.so.6 (gdb) bt #0 0x00007ffff585c868 in raise () from /lib64/libc.so.6 #1 0x00007ffff5843546 in abort () from /lib64/libc.so.6 #2 0x00007ffff56a589a in ?? () from /usr/lib64/libstdc++.so.6 #3 0x00007ffff56b106a in ?? () from /usr/lib64/libstdc++.so.6 #4 0x00007ffff56b10d5 in std::terminate() () from /usr/lib64/libstdc++.so.6 #5 0x00007ffff56b1368 in __cxa_throw () from /usr/lib64/libstdc++.so.6 #6 0x00007ffff5a98fa9 in qBadAlloc() () from /usr/lib64/libQt5Core.so.5 #7 0x00007ffff5a9e24b in ?? () from /usr/lib64/libQt5Core.so.5 #8 0x00007ffff5b5f722 in QString::append(QString const&) () from /usr/lib64/libQt5Core.so.5 #9 0x0000000000511cfc in SourceData::FileData::preprocess (this=0x78f4c0, pEncoding=<optimized out>, removeComments=false) at /usr/include/qt5/QtCore/qsharedpointer_impl.h:301 #10 0x00000000005128a4 in SourceData::readAndPreprocess (this=0x78f3d0, pEncoding=0x5cf750, bAutoDetectUnicode=<optimized out>) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/SourceData.cpp:466 #11 0x000000000048969a in KDiff3App::mainInit (this=0x95ffd0, pTotalDiffStatus=0xf880e8, inFlags=...) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/pdiff.cpp:131 #12 0x000000000048f83d in KDiff3App::slotFileOpen2 (this=0x95ffd0, errors=..., fn1=..., fn2=..., fn3=..., ofn=..., an1=..., an2=..., an3=..., pTotalDiffStatus=0xf880e8) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/pdiff.cpp:983 #13 0x000000000047b2f4 in QtPrivate::FunctorCall<QtPrivate::IndexesList<0, 1, 2, 3, 4, 5, 6, 7, 8>, QtPrivate::List<QStringList&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, TotalDiffStatus*>, void, void (KDiff3App::*)(QStringList&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, TotalDiffStatus*)>::call ( arg=<optimized out>, o=<optimized out>, f=<optimized out>) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:152 #14 QtPrivate::FunctionPointer<void (KDiff3App::*)(QStringList&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, TotalDiffStatus*)>::call<QtPrivate::List<QStringList&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, TotalDiffStatus*>, void> (arg=<optimized out>, o=<optimized out>, f=<optimized out>) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:185 #15 QtPrivate::QSlotObject<void (KDiff3App::*)(QStringList&, QString const&, QString const--Type <RET> for more, q to quit, c to continue without paging-- &, QString const&, QString const&, QString const&, QString const&, QString const&, TotalDiffStatus*), QtPrivate::List<QStringList&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, QString const&, TotalDiffStatus*>, void>::impl (which=<optimized out>, this_=<optimized out>, r=<optimized out>, a=<optimized out>, ret=<optimized out>) at /usr/include/qt5/QtCore/qobjectdefs_impl.h:418 #16 0x00007ffff5ce744d in ?? () from /usr/lib64/libQt5Core.so.5 #17 0x000000000044687e in DirectoryMergeWindow::startDiffMerge ( this=this@entry=0xc51f30, _t1=..., _t2=..., _t3=..., _t4=..., _t5=..., _t6=..., _t7=..., _t8=..., _t9=<optimized out>) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/build/src/kdiff3_autogen/EWIEGA46WW/moc_directorymergewindow.cpp:365 #18 0x000000000050bd0c in MergeFileInfos::compareFilesAndCalcAges ( this=this@entry=0xf880c0, errors=..., pOptions=..., pDMW=0xc51f30) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/MergeFileInfos.cpp:215 #19 0x0000000000471de3 in DirectoryMergeWindow::DirectoryMergeWindowPrivate::prepareListView (this=0x7f9530) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/directorymergewindow.cpp:1331 #20 0x0000000000472e0a in DirectoryMergeWindow::DirectoryMergeWindowPrivate::init ( this=0x7f9530, bDirectoryMerge=<optimized out>, bReload=<optimized out>) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/directorymergewindow.cpp:951 #21 0x000000000048d48f in KDiff3App::doDirectoryCompare (this=0x95ffd0, bCreateNewInstance=<optimized out>) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/pdiff.cpp:1628 #22 0x000000000048f40e in KDiff3App::slotFileOpen (this=this@entry=0x95ffd0) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/pdiff.cpp:898 #23 0x000000000045cb25 in KDiff3App::completeInit (this=this@entry=0x95ffd0, fn1=..., fn2=..., fn3=...) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/kdiff3.cpp:575 #24 0x000000000044e8c4 in KDiff3Shell::KDiff3Shell (this=this@entry=0x75e100, bCompleteInit=bCompleteInit@entry=true, __in_chrg=<optimized out>, __vtt_parm=<optimized out>) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/kdiff3_shell.cpp:64 --Type <RET> for more, q to quit, c to continue without paging-- #25 0x00000000004445f0 in main (argc=<optimized out>, argv=<optimized out>) at /tmp/slackrepo/etr/slackrepo.6KVtzD/build_kdiff3/kdiff3-1.10.6/src/main.cpp:201 (gdb) quit A debugging session is active. Inferior 1 [process 81111] will be killed. Quit anyway? (y or n) y EXPECTED RESULT No crash Yes I realize using kdiff3 to compare 1 GB files is nonsensical. My use case is to compare program output from multiple runs, where the output contains both huge files and small files that I actually want to compare. It's also nice to see if the huge files are exact matches or not (indicated by red or green in the directory overview pane). SOFTWARE/OS VERSIONS Linux/KDE Plasma: Slackware 15.0 (available in About System) KDE Plasma Version: 5.23.5 KDE Frameworks Version: 5.90.0 Qt Version: 5.15.3 ADDITIONAL INFORMATION I can currently work around this bug by ensuring "Binary Comparison" File Comparison Mode is set. I modified the SlackBuild from here https://slackbuilds.org/repository/15.0/development/kdiff3/ by changing the line: -DCMAKE_BUILD_TYPE=Release .. to -DCMAKE_BUILD_TYPE=Debug .. and also commenting out the 2 lines that strip executable and object files: #find $PKG | xargs file | grep -e "executable" -e "shared object" | grep ELF \ # | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null || true to generate a (hopefully) useful backtrace. The observed behavior is the same for Release and Debug builds of kdiff3. -- You are receiving this mail because: You are watching all bug changes.