Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Python bindings: various bounds checking failures (maybe arbitrary memory access?) #5993

Open
6 tasks done
AllSeeingEyeTolledEweSew opened this issue Feb 18, 2021 · 1 comment
Milestone

Comments

@AllSeeingEyeTolledEweSew
Copy link
Contributor

AllSeeingEyeTolledEweSew commented Feb 18, 2021

The following code snippets wrongly succeed. It looks like some bounds are not checked when they should be, resulting in unintentional memory access.

  • create_torrent.set_hash() with a short buffer. This succeeds, and create_torrent.generate() shows the piece gets set to be the short buffer plus some garbage data:
fs = file_storage()
fs.add_file("test.txt", 1024)
ct = create_torrent(fs)
ct.set_hash(0, b"a")  # should raise ValueError
  • create_torrent.set_file_hash(), similarly:
fs = file_storage()
fs.add_file("test.txt", 1024)
ct = create_torrent(fs)
ct.set_file_hash(0, b"a")  # should raise ValueError
  • sha1_hash(), similarly:
sha1_hash(b"a")  # should raise ValueError
  • torrent_info.hash_for_piece() with an invalid index wrongly succeeds. This seems to read arbitrary memory...
ti = torrent_info({b"info": {
    b"name": b"test.txt",
    b"length": 1024,
    b"piece length": 16384,
    b"pieces": b"a" * 20,
}})
ti.hash_for_piece(1)  # should raise ValueError
ti.hash_for_piece(-1)  # should raise ValueError
  • session.dht_put_mutable_item(b"short", b"short", b"data", b"salt"): Should raise ValueError if public or private key arguments are the wrong length
  • session.dht_get_mutable_item(b"short", b"salt"): Should raise ValueError if public key argument is wrong length

I'm finished writing new unit tests and won't add any more items to this issue.

@arvidn arvidn added this to the 1.2.14 milestone Apr 8, 2021
@arvidn arvidn modified the milestones: 1.2.14, 1.2.15 Jun 7, 2021
@AllSeeingEyeTolledEweSew
Copy link
Contributor Author

Should I close this? Or wait until it's merged to RC_1_2, since it's on a 1.2 milestone?

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

No branches or pull requests

2 participants