Skip to content

fix some gpg handling like TypeError: 'NamedFile' object is not iterable#60

Open
josch wants to merge 6 commits into
yoctoproject:mainfrom
josch:gpg-namedfile
Open

fix some gpg handling like TypeError: 'NamedFile' object is not iterable#60
josch wants to merge 6 commits into
yoctoproject:mainfrom
josch:gpg-namedfile

Conversation

@josch
Copy link
Copy Markdown

@josch josch commented May 1, 2026

When accidentally attempting to download a image and bmap file from gitlab without access privileges me and @mntmn ran into a couple of problems which are fixed in this MR:

  • src/bmaptool/CLI.py: add iter to NamedFile()
  • src/bmaptool/BmapCopy.py: stop processing after error position was reached
  • src/bmaptool/BmapCopy.py: decode binary string
  • src/bmaptool/TransRead.py: error out if subprocess exited with non-zero
  • src/bmaptool/CLI.py: manually extract plaintext if gpg is not available

josch added 6 commits May 1, 2026 20:25
Otherwise, when attempting to read an invalid bmapfile, the exception
handler throws an exception itself:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/bmaptool/BmapCopy.py", line 400, in _parse_bmap
    self._xml = ElementTree.parse(self._f_bmap)
                ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/xml/etree/ElementTree.py", line 1210, in parse
    tree.parse(source, parser)
    ~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/xml/etree/ElementTree.py", line 573, in parse
    self._root = parser._parse_whole(source)
                 ~~~~~~~~~~~~~~~~~~~^^^^^^^^
xml.etree.ElementTree.ParseError: mismatched tag: line 106, column 2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/bmaptool", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/usr/lib/python3/dist-packages/bmaptool/CLI.py", line 947, in main
    args.func(args)
    ~~~~~~~~~^^^^^^
  File "/usr/lib/python3/dist-packages/bmaptool/CLI.py", line 637, in copy_command
    writer = BmapCopy.BmapCopy(image_obj, dest_obj, bmap_obj, image_size)
  File "/usr/lib/python3/dist-packages/bmaptool/BmapCopy.py", line 286, in __init__
    self._parse_bmap()
    ~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/bmaptool/BmapCopy.py", line 405, in _parse_bmap
    for num, line in enumerate(self._f_bmap):
                     ~~~~~~~~~^^^^^^^^^^^^^^
TypeError: 'NamedFile' object is not iterable
…ached

On very large input, this stalls for a long time unnecessarily. Since
this is handling input which is invalid XML it is likely something
completely different, including multi gigabyte binary files.
Without decoding, the line remains binary type which means that it is
printed to the user as b"..." and newlines appear as \n instead of as
real line breaks.
Otherwise, this will finish successfully even though it wrote out
nothing:

$ echo foobar > test.gz
$ bmaptool copy --nobmap test.gz out.img
bmaptool: info: no bmap given, copy entire image to 'out.img'

gzip: stdin: not in gzip format
bmaptool: info: synchronizing 'out.img'
bmaptool: info: copying time: 0.0s, copying speed 0 bytes/sec
$ stat -c %s out.img
0
Otherwise, even with --no-sig-verify, the user will get:

bmaptool: ERROR: Cannot verify GPG signature without GPG
@josch josch force-pushed the gpg-namedfile branch 2 times, most recently from e047269 to 67695cf Compare May 4, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant