RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1073239 - createrepo's modifyrepo fails when passed a minidom.Document
Summary: createrepo's modifyrepo fails when passed a minidom.Document
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: createrepo
Version: 6.6
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Valentina Mukhamedzhanova
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-03-06 06:01 UTC by Mathieu Bridon
Modified: 2017-12-06 10:45 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-12-06 10:45:48 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Simple reproducer (366 bytes, text/plain)
2014-03-06 06:04 UTC, Mathieu Bridon
no flags Details

Description Mathieu Bridon 2014-03-06 06:01:53 UTC
Description of problem:
RepoMetadata().add() can take either a minidom.Document instance, or a string (the path to the metadata file to add):

    def add(self, metadata, mdtype=None):
        """ Insert arbitrary metadata into this repository.
            metadata can be either an xml.dom.minidom.Document object, or
            a filename.
        """
        md = None
        if not metadata:
            raise MDError, 'metadata cannot be None'
        if isinstance(metadata, minidom.Document):
            md = metadata.toxml()
            mdname = 'updateinfo.xml'
        elif isinstance(metadata, str):
            if os.path.exists(metadata):

So the "metadata" variable contains either a file path (string) or a minidom.Document instance.

Further on, that "metadata" variable is passed to the Yum API:

        open_csum = checksum(self.checksum_type, metadata)

In that checksum function, our "metadata" becomes the "file" variable:

    def checksum(sumtype, file, CHUNK=2**16, datasize=None):
        """takes filename, hand back Checksum of it
           sumtype = md5 or sha/sha1/sha256/sha512 (note sha == sha1)
           filename = /path/to/file
           CHUNK=65536 by default"""
    
        # chunking brazenly lifted from Ryan Tomayko
        try:
            if type(file) not in types.StringTypes:
                fo = file # assume it's a file-like-object
            else:
                fo = open(file, 'r', CHUNK)

But that checksum function assumes that the "file" (i.e, our "metadata") is either a string (the file path), or.. a file-like object.

In other words, it doen't handle at all minidom.Document instances.

As a result, when trying to add a new metadata, passing a minidom.Document instance (as Bodhi does), we get:

    Traceback (most recent call last):
      File "./testmodifyrepo.py", line 156, in <module>
        main(sys.argv[1], sys.argv[2])
      File "./testmodifyrepo.py", line 152, in main
        repomd.add(metadata, mdtype="updateinfo")
      File "/usr/share/createrepo/modifyrepo.py", line 134, in add
        open_csum = checksum(self.checksum_type, metadata)
      File "/usr/lib/python2.6/site-packages/yum/misc.py", line 328, in checksum
        while data.read(fo, CHUNK):
      File "/usr/lib/python2.6/site-packages/yum/misc.py", line 264, in read
        data = fo.read(size)
    AttributeError: Document instance has no attribute 'read'

The minidom.Document instance was incorrectly assumed to be a file-like object by yum.misc.checksum()...

Version-Release number of selected component (if applicable):
  createrepo-0.9.9-18.nb5.0.0.noarch
  yum-3.2.29-40.nb5.0.1.noarch

I can see a few things that could be done, here:

1. RepoMetadata.add could call yum.misc.checksum properly, passing it either a string (path to the file) or a file-like object, in all cases
2. yum.misc.checksum could learn to handle minidom.Document instances

So I'm not sure if the bug really is in createrepo or in yum, but I'm opening it against createrepo as it''s the component that is impacted by the problem.

Comment 1 Mathieu Bridon 2014-03-06 06:04:23 UTC
Created attachment 871219 [details]
Simple reproducer

Comment 2 Mathieu Bridon 2014-03-06 06:16:57 UTC
My apologies for the rpm versions above, these are on an EL6 rebuild.

However, there are no downstream changes compared with the RHEL6 source rpms, they are merely rebuilt.

The problem also exists on RHEL6 proper.

Comment 4 Valentina Mukhamedzhanova 2014-03-06 15:42:52 UTC
The following patch for createrepo fixes the problem:
--- modifyrepo.py.old	2014-03-06 13:01:34.027395020 +0100
+++ modifyrepo.py	2014-03-06 13:02:08.423462876 +0100
@@ -36,6 +36,7 @@ from yum.misc import checksum
 from yum.repoMDObject import RepoMD, RepoMDError, RepoData
 from xml.dom import minidom
 from optparse import OptionParser
+from cStringIO import StringIO
 
 
 class RepoMetadata:
@@ -129,7 +130,7 @@ class RepoMetadata:
         newmd.close()
         print "Wrote:", destmd
 
-        open_csum = checksum(self.checksum_type, metadata)
+        open_csum = checksum(self.checksum_type, StringIO(md))
         csum, destmd = checksum_and_rename(destmd, self.checksum_type)
         base_destmd = os.path.basename(destmd)

Comment 5 Mathieu Bridon 2014-03-07 04:00:47 UTC
Yup, confirming that this patch fixes the issue for me as well. (but then, I end up falling into bug #1073256)

Note that this is fixed (differently) in the createrepo from Fedora 20, so another option would be to just upgrade the RHEL 6 package to the Fedora one (but I can easily understand as that might not be desired :) )

Comment 6 Valentina Mukhamedzhanova 2014-03-07 09:00:25 UTC
I have tested your reproducer on Fedora, and it gives me all kinds of different tracebacks :) And even after fixing those tracebacks the open_checksum isn't calculated correctly. So there will be an upstream fix for this too.

Comment 7 Mathieu Bridon 2014-03-07 09:08:00 UTC
Right, my reproducer doesn't work on Fedora because you need to set the attributes repomd.unique_md_filenames, repomd.compress...

But that's a problem with my reproducer being too simple. ;)

I didn't see that the checksum was incorrectly calculated, though, but I'll happily trust you on that.

Thanks for being so prompt in answering though.

Any ETA for when the updated package would be pushed as an update?

Comment 8 Jan Zeleny 2014-03-07 14:30:03 UTC
> Any ETA for when the updated package would be pushed as an update?

Actually we can't promise you anything, we can't even guess at this point. There is an internal process to be followed that includes a lot of prioritization in various departments. If you have a customer account, you can escalate this bug through your support representative to give it higher priority.

Thanks for understanding.

Comment 9 Mathieu Bridon 2014-03-07 15:45:08 UTC
Sure, I understand. :)

I was wondering if you had an ETA, but if you don't, well, we'll work around the bug in Bodhi. ;)

Thanks again.

Comment 11 Jan Kurik 2017-12-06 10:45:48 UTC
Red Hat Enterprise Linux 6 is in the Production 3 Phase. During the Production 3 Phase, Critical impact Security Advisories (RHSAs) and selected Urgent Priority Bug Fix Advisories (RHBAs) may be released as they become available.

The official life cycle policy can be reviewed here:

http://redhat.com/rhel/lifecycle

This issue does not meet the inclusion criteria for the Production 3 Phase and will be marked as CLOSED/WONTFIX. If this remains a critical requirement, please contact Red Hat Customer Support to request a re-evaluation of the issue, citing a clear business justification. Note that a strong business justification will be required for re-evaluation. Red Hat Customer Support can be contacted via the Red Hat Customer Portal at the following URL:

https://access.redhat.com/


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