CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Strange MD5 behaviour

 



perl4me2
New User

Jan 19, 2009, 1:40 PM

Post #1 of 2 (997 views)
Strange MD5 behaviour Can't Post

Hello,

I have a strange problem I need help with.

Scenario:

Program1:
opens a binary file,
:loop
reads 1024 bytes with OFFSET,
runs a MD5,
save MD5 to a textfile,
increment OFFSET by bytes read,
loop until end of file.

Program2:
:loop
opens a binary file,
reads 1024 bytes with OFFSET,
runs a MD5,
save MD5 to a textfile,
close the file,
increment OFFSET by bytes read,
loop until end of file.

Only the first MD5's are equal between textfiles, any idea why?
Note the difference between program 1 and 2, number 1 reads while the file is open, 2 re-opens and positions with OFFSET.
If in program2 I read the exact previous block and then read the following block the MD5 equals.

So it sounds like OFFSET is not working (neither is seek) as it should.


perl4me2
New User

Jan 20, 2009, 2:28 AM

Post #2 of 2 (990 views)
Re: [perl4me2] Strange MD5 behaviour [In reply to] Can't Post

Solved... a very stupid mistake to make...

$buffer = "";
seek (INF,$position,0);
$fsize = read (INF, $buffer, $size, $position);


When reading a binary block from a file, seek is not broken, but you can't use a position parameter at both functions, if you do you're buffer will get pre-pended with zero bytes until the start of the data read.

Ie. read with position 100:

0,0,0,0,0,0,0,0(up to 99) then the data read. (this way a md5 always fails and the buffer gets larger and larger)

$buffer = "";
seek (INF,$position,0);
$fsize = read (INF, $buffer, $size);


This works SlyLaugh me happy camper.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives