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: re reads an uninitialized memory
Type: Stage:
Components: Extension Modules Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: niemeyer Nosy List: ishimoto, loewis, niemeyer, nnorwitz
Priority: normal Keywords: patch

Created on 2003-06-17 16:53 by ishimoto, last changed 2022-04-10 16:09 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
sre_readerr.patch ishimoto, 2003-06-17 16:53
Messages (7)
msg44054 - (view) Author: Atsuo Ishimoto (ishimoto) * Date: 2003-06-17 16:53
With this script, re reads from an address beyond the 
end of the string.

>>> import re
>>> r = re.compile(r"\b1")
>>> print r.search('a', 1)

See assert() in the attached patch to see where 
incorrect memory reading occurs.
This patch looks fix the problem, but I'm not sure this is 
correct answer.
msg44055 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2003-06-21 13:30
Logged In: YES 
user_id=21627

Gustavo, can your review this code?
msg44056 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2003-06-21 23:28
Logged In: YES 
user_id=7887

Atsuo, can you please describe what problem you're trying to
fix!? In other words, can you provide some code which breaks
SRE?

Your assertion doesn't seem to make sense in this place,
since having ptr outside the boundaries of beginning/end
*is* accepted. Notice how "ptr < state->end" is checked
before using ptr[0].

I'm closing this bug as invalid. If you have something you
belive to prove there's a bug in this place, please reopen
this bug.

Thank you very much for taking the time to fill this bug.
msg44057 - (view) Author: Atsuo Ishimoto (ishimoto) * Date: 2003-06-22 02:14
Logged In: YES 
user_id=463672

Sorry for my lack of infomation.

While ptr outside the boundaries is legal, but fetching from 
there is
not. One example of problem is using SRE for mmap object. 
This script
causes an application error under my w2k box.

open("tstfile", "wb").write('a'*4096)
import mmap
f = open("tstfile", "rb")
xx = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
import re
r = re.compile(r"\b1")
r.search(xx, len(xx))
msg44058 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2003-06-22 20:33
Logged In: YES 
user_id=7887

Now I can see the problem. The current test doesn't
contemplate a broken ptr/end pair. Your code is addressing
the right problem, but the right way to fix this seems to be
to avoid that branch completely, unless pattern[3] > 1
(unlike the current > 0).

Thank you very much for your patch and your insistence!
msg44059 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2003-06-26 14:47
Logged In: YES 
user_id=7887

Fixed in Modules/_sre.c:2.99.

Thanks!
msg44060 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2003-06-27 14:08
Logged In: YES 
user_id=33168

Gustavo, can you add a test case as well?  Thanks.
History
Date User Action Args
2022-04-10 16:09:16adminsetgithub: 38669
2003-06-17 16:53:15ishimotocreate