Public bug reported:

/usr/bin/bson2json opens the input file in text mode:

    ifh = open(sys.argv[1])

This inevitably causes the tool to crash, e.g.:
```
/tmp$ echo '{}' >x.json
/tmp$ json2bson x.json >x.bson
/tmp$ bson2json x.bson 
Traceback (most recent call last):
  File "/usr/bin/bson2json", line 84, in <module>
    data = fh_loaders[itype](ifh)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/bson2json", line 24, in <lambda>
    "bson": lambda fh: next(bson.decode_file_iter(fh)),
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/bson/__init__.py", line 1159, in 
decode_file_iter
    obj_size = _UNPACK_INT_FROM(size_data, 0)[0] - 4
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'str'
```

The problem vanishes if I change the call to:

    ifh = open(sys.argv[1], 'rb')

Looks like the broken `open` call is specific to debian/ubuntu, I see no
traces of it in the upstream github repo
(https://github.com/grawity/code/blob/master/bin/reserialize)

** Affects: reserialize (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2083618

Title:
  bson2json opens files in text mode

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/reserialize/+bug/2083618/+subscriptions


-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to