Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Failed to scan RPM #3489

Closed
pombredanne opened this issue Aug 16, 2023 · 3 comments · Fixed by #3520
Closed

Failed to scan RPM #3489

pombredanne opened this issue Aug 16, 2023 · 3 comments · Fixed by #3520

Comments

@pombredanne
Copy link
Member

Reported by @chinyeungli

Using http://mirror.centos.org/centos/7/os/x86_64/Packages/apache-commons-io-2.4-12.el7.noarch.rpm

$ SCANCODE_DEBUG_PACKAGE_API=yes  scancode -p apache-commons-io-2.4-12.el7.noarch.rpm --yaml  -
Setup plugins...
Collect file inventory...
Scan files for: packages with 1 process(es)...
[--------------------] 0_parse:.is_datafile: /home/pombreda/w421/scancode.io/apache-commons-io-2.4-12.el7.noarch.rpm
[####################] 2                                                 
headers:
    -   tool_name: scancode-toolkit
        tool_version: 32.0.6
        options:
            input:
                - apache-commons-io-2.4-12.el7.noarch.rpm
            --package: yes
            --yaml: '-'
        notice: |
            Generated with ScanCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
            OR CONDITIONS OF ANY KIND, either express or implied. No content created from
            ScanCode should be considered or used as legal advice. Consult an Attorney
            for any legal advice.
            ScanCode is a free software code scanning tool from nexB Inc. and others.
            Visit https://github.com/nexB/scancode-toolkit/ for support and download.
        start_timestamp: '2023-08-16T083251.861239'
        end_timestamp: '2023-08-16T083256.129079'
        output_format_version: 3.0.0
        duration: '4.267852544784546'
        message:
        errors:
            - 'Path: apache-commons-io-2.4-12.el7.noarch.rpm'
        warnings: []
        extra_data:
            system_environment:
                operating_system: linux
                cpu_architecture: 64
                platform: Linux-4.15.0-214-generic-x86_64-with-glibc2.23
                platform_version: '#225~16.04.1-Ubuntu SMP Mon Jul 17 10:25:38 UTC 2023'
                python_version: "3.9.10 (main, Jan 29 2022, 10:01:49) \n[GCC 5.4.0 20160609]"
            spdx_license_list_version: '3.21'
            files_count: 1
packages: []
dependencies: []
files:
    -   path: apache-commons-io-2.4-12.el7.noarch.rpm
        type: file
        package_data: []
        for_packages: []
        scan_errors:
            - |
                ERROR: for scanner: packages:
                ERROR: Unknown error:
                Traceback (most recent call last):
                  File "/scancode-toolkit/scancode/interrupt.py", line 91, in interruptible
                    return NO_ERROR, func(*(args or ()), **(kwargs or {}))
                  File "/scancode-toolkit/scancode/api.py", line 303, in get_package_data
                    package_datas = _get_package_data(
                  File "/scancode-toolkit/scancode/api.py", line 261, in _get_package_data
                    return recognize_package_data(
                  File "/scancode-toolkit/packagedcode/recognize.py", line 66, in recognize_package_data
                    return list(_parse(location, datafile_handlers=datafile_handlers))
                  File "/scancode-toolkit/packagedcode/recognize.py", line 88, in _parse
                    for parsed in handler.parse(location):
                  File "/scancode-toolkit/packagedcode/rpm.py", line 289, in parse
                    evr = EVR(
                  File "/scancode-toolkit/packagedcode/rpm.py", line 99, in __new__
                    if epoch and epoch.strip() and not epoch.isdigit():
                AttributeError: 'int' object has no attribute 'strip'

Scanning done.
Some files failed to scan properly:
Path: apache-commons-io-2.4-12.el7.noarch.rpm
Summary:        packages with 1 process(es)
Errors count:   1
Scan Speed:     10.25 files/sec. 
Initial counts: 1 resource(s): 1 file(s) and 0 directorie(s) 
Final counts:   1 resource(s): 1 file(s) and 0 directorie(s) 
Timings:
  scan_start: 2023-08-16T083251.861239
  scan_end:   2023-08-16T083256.129079
  setup_scan:licenses: 4.13s
  setup: 4.13s
  total: 4.28s

The issue is with this code:

 if epoch and epoch.strip() and not epoch.isdigit():

it should be more or less

if epoch and not isinstance(epoch, int):
    if isinstance(epoch, str) and epoch.strip() and not epoch.isdigit():
@OmkarPh
Copy link
Contributor

OmkarPh commented Sep 22, 2023

Hi
Is anybody working on this issue ?

@OmkarPh
Copy link
Contributor

OmkarPh commented Sep 22, 2023

Since we're also doing this later:

        if self.epoch:
            vr = ':'.join([self.epoch, vr])
        return vr

we'll have to store epoch as string ?

like this maybe:

def __new__(self, version, release=None, epoch=None):
        """
        note: the sort order of the named tuple is the sort order.
        But for creation we put the rarely used epoch last with a default to None.
        """
        # print("Epoch: ", epoch, type(epoch))

        if epoch and not isinstance(epoch, int):
            if isinstance(epoch, str) and epoch.strip() and not epoch.isdigit():
                raise ValueError('Invalid epoch: must be a number or empty.')
        if not version:
            raise ValueError('Version is required: {}'.format(repr(version)))

        # print("Final Epoch: ", str(epoch), type(str(epoch)))
        return super().__new__(EVR, str(epoch), version, release)

@pombredanne
Copy link
Member Author

Hi Is anybody working on this issue ?

Nope... all yours!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants