Recent

Author Topic: POssible bug introduced into FindAllFiles or TFileSearcher?  (Read 5307 times)

Gizmo

  • Hero Member
  • *****
  • Posts: 831
POssible bug introduced into FindAllFiles or TFileSearcher?
« on: November 02, 2011, 04:38:01 pm »
I'm not sure if it's my code, or if a bug has recently been introduced into either TFileSearcher or the FindAllFiles procedure. I expect it's my code, but for the life of me, I can't see where it is, and the behaviour is unusual. Let me explain...

I have created a program called QuickHash (https://sourceforge.net/projects/quickhash/) using Lazarus and FPC. It's a program that traverses directories of files and hashes the files using MD5, SHA1, SHA256 or SHA512 algorithms. MD5 and SHA1 utilise the built in FPC procedures. SHA256 and SHA512 utilise the DCPCrypt procedures. 

I've recently updated to Lazarus 0.9.31 and FPC2.5.1. When I compile my program on Linux, everything works as expected and it always has done. Files are found in a directory, processed, and output to a StringGrid. However, on Windows, that very same code, when compiled into an exe, results in the same hash value being generated for every file found, but only when I use MD5 or SHA1. If I use SHA256 or SHA512, it works fine. I stress again that this problem DOES NOT occur on the Linux binary. Only the Windows one. For this reason I wondered if a bug has been introduced into one of the file finding routines so that different results are fed back for Windows systems whereas Linux systems are handled differenty?  On the Linux system, I can jump between any of the 4 hashing algorithms, and correct hashes are computed for every file.

If anyone can spot the bug in my code (https://sourceforge.net/projects/quickhash/files/SourceCode/), I'd sure appreciate it! But if not, and if anyone can confirm, I'll file a bug.

Ted

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: POssible bug introduced into FindAllFiles or TFileSearcher?
« Reply #1 on: November 02, 2011, 07:01:16 pm »
Hi Ted,

Just wanted you to know: there doesn't seem to be any code in that SVN repository...

So the problem occurs when you use the built-in FPC hash methods, not the DPCrypt methods & only on Windows, right?

You might want to check the bugtracker for those keywords...

I had a quick look through Lazarus svn log and only found this (quick search for findallfiles):
Quote
r13223 | tombo | 2007-12-08 15:53:43 +0100
LCL Masks: use PathSpearator constant
LCL FileUtil: implemented TFileSearcher, FindAllFiles
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: POssible bug introduced into FindAllFiles or TFileSearcher?
« Reply #2 on: November 02, 2011, 09:03:15 pm »
Quote
So the problem occurs when you use the built-in FPC hash methods, not the DPCrypt methods & only on Windows, right?

Yes. Though that said, I have always used the built-in FPC methods. It's just that now I've moved them to part of my own function that is called by a group of 4 radio buttons. Previously, I only had one option (use of SHA1 hash). The following pseudo code illustrates:
Code: [Select]
if Checkbox1.Checked = true then
  MD5
else if
 if Checkbox2.Checked = true then
  SHA1
else if
 if Checkbox3.Checked = true then
  SHA256 (from DCPCrypt)
else if
 if Checkbox4.Checked = true then
  SHA512 (from DCPCrypt)
else
  Error Message

PS - the source code is in the unit1.pas file in the zip?

It must be something to do with the way I'm passing data from the streams. I have no freaking idea why it's fine in Linux and not on Windows though. Bloody Windows. It does my head in.

Ted

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4552
  • I like bugs.
Re: POssible bug introduced into FindAllFiles or TFileSearcher?
« Reply #3 on: November 03, 2011, 12:30:57 am »
Using a debugger you can find out if the problem is in FindAllFiles or in the hash routines or somewhere else.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Gizmo

  • Hero Member
  • *****
  • Posts: 831
Re: POssible bug introduced into FindAllFiles or TFileSearcher?
« Reply #4 on: November 03, 2011, 10:55:12 pm »
Solved.

It turned out to be because I was using a filestream when the function was only being passed a path to the file in the form of a string. So I was openeing the stream but not actually using it. Though why it worked on Linux is a mystery.

The version I have now works on both platforms regardless, which was my aim.

Thanks to Laksen in IRC who pointed this out to me.

Ted

 

TinyPortal © 2005-2018