This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Problem at the end of misformed mailbox
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: barry Nosy List: barry, jlgijsbers, loewis, rpeyron, tim.peters
Priority: normal Keywords: patch

Created on 2002-11-03 16:50 by rpeyron, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Messages (6)
msg41527 - (view) Author: Rémi Peyronnet (rpeyron) Date: 2002-11-03 16:50
I had a problem with a not well formed mailbox (maybe 
ambiguous carriage return chars, due to both use under 
windows and linux) : the function mailbox.readlines 
(lib/mailbox.py:66) entered in an indefinite cycle.

I found that the self.stop value was too big for the file, 
and that the index of self.pos could not go that far. The 
function readlines will call ever and ever readline, which 
will return always the same 1-length string.

I solved this by comparing the fp.pos before and after 
the read operation. If it the same, we re probably at the 
end of the file, or there is a problem, and we should go 
out.

As I do not know much about the Python internals, the 
following patch may not be good :

C:\Python222\Lib>diff "Copie de mailbox.py"  mailbox.py
63c63,68
<         self.pos = self.fp.tell()
---
>         data = self.fp.readline(length)
>         self_fp_tell = self.fp.tell()
>         if self.pos == self_fp_tell:
>           return ''
>         else:
>           self.pos = self_fp_tell

Regards
msg41528 - (view) Author: Rémi Peyronnet (rpeyron) Date: 2003-12-27 18:48
Logged In: YES 
user_id=641559

This problem seems to exist in 2.3 version too.
msg41529 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2004-03-21 20:03
Logged In: YES 
user_id=31435

Assigned to Barry.  Maybe y'all can polish this one off during 
the email sprint?
msg41530 - (view) Author: Johannes Gijsbers (jlgijsbers) * (Python triager) Date: 2004-11-11 20:29
Logged In: YES 
user_id=469548

Rémi, could you attach the mailbox (or a similar mailbox)
that triggers the problem? 
msg41531 - (view) Author: Rémi Peyronnet (rpeyron) Date: 2004-11-22 22:51
Logged In: YES 
user_id=641559

Sorry, I did not keep the mailbox. I may re-use this script
in a few weeks/months, and if it does the same thing I will
attach one.
msg41532 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2006-11-05 18:47
Logged In: YES 
user_id=21627

After reviewing the code, I cannot see a reason for this
problem to occur. self.stop originates from an earlier
fp.tell() call, so it should be at most equal to the file
size. Later readline calls should manage to read all of the
file, then fp.tell should report the same value. The only
way this might happen is that self.stop was somehow modified
outside the standard library, or a _Subfile was created
externally; I don't think the library should work around
such a problem.

So closing this as "works for me". If somebody manages to
reproduce the problem, please include precise instructions
on how to reproduce it.
History
Date User Action Args
2022-04-10 16:05:48adminsetgithub: 37403
2002-11-03 16:50:48rpeyroncreate