Note: This is a public test instance of Red Hat Bugzilla. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback at bugzilla.redhat.com.
Bug 1913465 - createrepo_c segfault when attempting to print PrimaryXmlFile or PrimarySqlite object after closing
Summary: createrepo_c segfault when attempting to print PrimaryXmlFile or PrimarySqlit...
Keywords:
Status: VERIFIED
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: createrepo_c
Version: 8.3
Hardware: x86_64
OS: Linux
low
low
Target Milestone: rc
: 8.0
Assignee: amatej
QA Contact: Jan Blazek
URL:
Whiteboard:
Depends On: 1951406
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-01-06 20:30 UTC by Ryan Mullett
Modified: 2021-06-29 08:49 UTC (History)
3 users (show)

Fixed In Version: createrepo_c-0.17.2-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed:
Type: Bug
Target Upstream Version:


Attachments (Terms of Use)
segfault from RHEL 8 test system illustrating the issue (7.49 MB, application/x-tar)
2021-01-06 20:30 UTC, Ryan Mullett
no flags Details

Description Ryan Mullett 2021-01-06 20:30:00 UTC
Created attachment 1745041 [details]
segfault from RHEL 8 test system illustrating the issue

Description of problem:
After calling the .close() method on a PrimaryXmlFile or PrimarySqlite object, calling __repr__ or __str__ results in a coredump

Version-Release number of selected component (if applicable):
createrepo_c-libs-0.15.11-2.el8.x86_64
python3-createrepo_c-0.15.11-2.el8.x86_64

Issue appears to be present in every release across 7 and 8.

How reproducible:
Always

Steps to Reproduce:
Example 1:
# python3 -c 'import createrepo_c; p = createrepo_c.PrimarySqlite("primary.sqlite"); p.close(); p.__str__()'
Segmentation fault (core dumped)

Example 2:
# python3 -c 'import createrepo_c; p = createrepo_c.PrimarySqlite("primary.sqlite"); p.close(); p.__repr__()'
Segmentation fault (core dumped)

Example 3:
# python3 -c 'import createrepo_c; p = createrepo_c.PrimaryXmlFile("primary.xml"); p.close(); p.__str__()'
Segmentation fault (core dumped)

Example 4:
# python3 -c 'import createrepo_c; p = createrepo_c.PrimaryXmlFile("primary.xml"); p.close(); p.__repr__()'
Segmentation fault (core dumped)

Actual results:
Segfault

Expected results:
After closing, the object should still be available to be read, as is standard for other python modules. For example:

# python -c 'p = open("items.xml"); p.close(); print(p.__str__())'
<_io.TextIOWrapper name='items.xml' mode='r' encoding='UTF-8'>

Additional info:
Looking around it appears that other methods that are fully implemented via this library go through a check to see if the object was already closed. They go through check_XmlFileStatus():

static int
check_XmlFileStatus(const _XmlFileObject *self)
{
    assert(self != NULL);
    assert(XmlFileObject_Check(self));
    if (self->xmlfile == NULL) {
        PyErr_SetString(CrErr_Exception,
            "Improper createrepo_c XmlFile object (Already closed file?).");
        return -1;
    }
    return 0;
}

However, the __repr__ and __str__ do not. This results in a segfault when they try to access the object which is NULL after having been closed.

Comment 1 Ryan Mullett 2021-01-06 20:34:06 UTC
One additional check that was performed, which I neglected to add to initial description is below. This is simply to illustrate that the issue is not the check_XmlFileStatus(). That function is working correctly for other functions which do call it:

# python3 -c 'import createrepo_c; p = createrepo_c.PrimaryXmlFile("backup-primary.xml"); p.close(); p.set_num_of_pkgs(5)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
createrepo_c.CreaterepoCError: Improper createrepo_c XmlFile object (Already closed file?).

Comment 4 amatej 2021-03-29 14:08:57 UTC
The previous PR was fixing just xmlfile I have made another one which also fixes sqlite and it prints the representation of a closed xmlfile/sqlite instead of throwing an exception.

In addition it adds unit test testing.

https://github.com/rpm-software-management/createrepo_c/pull/257


Note You need to log in before you can comment on or make changes to this bug.