frostwire / frostwire-jlibtorrent

A swig Java interface for libtorrent by the makers of FrostWire. Develop libtorrent based apps with the joy of coding in Java.
http://www.frostwire.com
MIT License
451 stars 138 forks source link

[crash] TorrentHandle.filePriorities() -> torrent_handle.get_file_priorities().get(n) broken #186

Closed gubatron closed 6 years ago

gubatron commented 6 years ago

screen shot 2017-11-07 at 7 19 22 pm

public Priority[] filePriorities() {
        download_priority_vector v = th.get_file_priorities();
        int size = (int) v.size();
        Priority[] arr = new Priority[size];
        for (int i = 0; i < size; i++) {
            arr[i] = Priority.fromSwig(v.get(i));
        }
        return arr;
    }

When Priority.fromSwig() received the swig value out of v.get(i), it receives a value that does not correspond to any of the expected Priority enums swig values.

screen shot 2017-11-07 at 7 08 39 pm

The swig values on each one of these enums are:

IGNORE -> int 0 NORMAL -> int 1 ... and so on.

When Priority.fromSwig(v.get(i)) is running, v.get(i) is passing something completely unexpected:

screen shot 2017-11-07 at 7 11 10 pm

and the loop ends up throwing an IllegalArgumentException("Invalid native value");

screen shot 2017-11-07 at 7 11 47 pm

The issue is clearly with the download_priority_vector object returned by th.get_file_priorities()

screen shot 2017-11-07 at 7 19 15 pm

screen shot 2017-11-07 at 7 19 22 pm

screen shot 2017-11-07 at 7 19 28 pm

The implementation of this method in torrent_handle.java is as follows:

public download_priority_vector get_file_priorities() {
    return new download_priority_vector(libtorrent_jni.torrent_handle_get_file_priorities(swigCPtr, this), true);
  }

I played manually with the libtorrent_jni code with the debugger with no luck, my guess is that this is deeper in the stack.

gubatron commented 6 years ago

oh I think you got it already https://github.com/frostwire/frostwire-jlibtorrent/commit/1cdfdc1b91685cd9a43b12cb6aa704bb41cf9341