Solution: Serious bug on perl 5.8 may cause file/folder corruption

Paulo Matos <[email protected]> Thu, 11 Sep 2003 01:50:39 +0100 (WEST)
Newsgroups gmane.mail.neomail.general
Message-ID <[email protected]>
Hello again!

* This post is intended to answer to questions and misbeahvior reports 
such as stated in messages like:

+ Dianna Brown's post ("Corrupt folder", 2003-07-02)
http://sourceforge.net/mailarchive/forum.php?thread_id=2704006&forum_id=7155

+ When I try to read a message after a period of time, another message 
is shown instead of the one I clicked?

+ Scott Raun's post ("Problem using Pine folder mode", 2003-09-06)
http://sourceforge.net/mailarchive/forum.php?thread_id=3087517&forum_id=7155

+ Pine does not recognize anymore a folder I moved some messages, now I 
have a huge message with all inside?


* And Why is this happening?

This misterious folder corruptions are caused because there is a bug in 
tell() in perl 5.8 which would return wrong offset if it is called after 
open(F, ">>file");

This is a serious bug which may corrupt the folder file in some cases when 
using perl 5.8 (eg: RedHat 8.0 ships it by default)


* The Solution:

There is only a quick fix, but it implies changing the code. I would not 
call it solution but a safer way of programming... 

Using
	open(F, "+>>file");	# same behavior as "a+" on "C"'s fopen() 
instead of 
	open(F, ">>file");
seems to address the issue.

A way to do this changes quickly, will be:

# perl perl -pi'.bak' -e 's#>>#+>>#gs' neomail.pl neomail-prefs.pl

this will replace any occurances of ">>" with "+>>", and will save a copy 
of the files with the '.bak' appended to its name.


Watch the complete perl bug report here:
	
http://rt.perl.org/rt2//Ticket/Display.html?id=18711


Regards,

-- 
Paulo Matos




-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf