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
446 stars 137 forks source link

bitfield.get_bit SIGSEGV #146

Closed proninyaroslav closed 7 years ago

proninyaroslav commented 7 years ago

I get many messages with error in Google Play. This error is not caught with the help of ACRA.

Build fingerprint: 'lge/g2_open_cn/g2:4.4.2/KOT49I.D80220e/D80220e.1394898443:user/release-keys'
Revision: '10'
pid: 2286, tid: 2286, name: rentTaskService  >>> org.proninyaroslav.libretorrent:TorrentTaskService <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000030
    r0 00080000  r1 0000002c  r2 80000000  r3 00000000
    r4 57afffe0  r5 4180b028  r6 00000007  r7 5776bcb0
    r8 becd6318  r9 5776bca0  sl 4180b038  fp becd632c
    ip 610e8ce0  sp becd6310  lr 417434d0  pc 610e8d04  cpsr 800e0010
    d0  0000000000000000  d1  0000000000000000
    d2  0000000000000000  d3  0000000000000000
    d4  0000000000004024  d5  0000000000004025
    d6  0000000000004026  d7  0000000000004027
    d8  0000000042c80000  d9  0000000000000000
    d10 00000000000002c8  d11 4086400000000000
    d12 0000000000000000  d13 0000000000000000
    d14 0000000000000000  d15 0000000000000000
    d16 0000000d00000011  d17 0000000000000000
    d18 42ab2fb042ab2c20  d19 42b234d042b23128
    d20 42fc1c3842fc1888  d21 42cb70b842fc1fc8
    d22 42d0742842cb7500  d23 42c7db2042d077b8
    d24 0000000000000000  d25 0000000000000000
    d26 0000000000000000  d27 0909090909090909
    d28 0100010001000100  d29 0100010001000100
    d30 4024000000000000  d31 4024000000000000
    scr 20000010

backtrace:
    #00  pc 001c1d04  /data/app-lib/org.proninyaroslav.libretorrent-1/libjlibtorrent.so (Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_bitfield_1get_1bit+36)
    #01  pc 000204cc  /system/lib/libdvm.so (dvmPlatformInvoke+112)
    #02  pc 000512af  /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+398)
    #03  pc 00000214  /dev/ashmem/dalvik-jit-code-cache (deleted)

code around pc:
    610e8ce4 e5921000 e1a02fc0 e0802da2 e200001f  
    610e8cf4 e1a022c2 e0811102 e3a02102 e1a00032  
    610e8d04 e5911004 e6bf0f30 e0110000 13000001  
    610e8d14 e12fff1e e59d0004 e5921000 e1a02fc0  
    610e8d24 e0802da2 e200001f e1a022c2 e0811102  
    610e8d34 e3a02102 e1e00032 e5913004 e6bf0f30  
    610e8d44 e0030000 e5810004 e12fff1e e59d0004  
    610e8d54 e5921000 e1a02fc0 e0802da2 e200001f  
    610e8d64 e1a022c2 e0811102 e3a02102 e1a00032  
    610e8d74 e5913004 e6bf0f30 e1830000 e5810004  
    610e8d84 e12fff1e e92d4830 e28db008 e1a04000  
    610e8d94 e1a00002 ebff3b65 e8bd8830 e1a05001  
    610e8da4 ebff392e e3550002 1a00000a e5901000  
    610e8db4 e5911008 e12fff31 e1a02000 e1a00004  
    610e8dc4 e3a01003 ebffaf0d ea000007 e1a04000  
    610e8dd4 ebff3925 ea000009 e59f0030 e08f2000  

code around lr:
    417434b0 3497c004 3488c004 3afffff9 e2888004  
    417434c0 eafffff9 e899000c e59bc00c e12fff3c  
    417434d0 e3560000 159bc010 e24bd014 188c0003  
    417434e0 e8bd8bc0 e1a0ce22 e59b6008 e2866001  
    417434f0 e3a02000 e4d6c001 e35c0000 0a000007  
    41743500 e2822001 e35c0044 135c004a 1afffff8  
    41743510 e3120001 12822001 02822002 eafffff4  
    41743520 e2522002 43b02000 0affffe5 e04dd102  
    41743530 e3cdd004 e1a07009 e1a0800d e59b6008  
    41743540 e2866001 e2877008 e4d6c001 e35c0044  
    41743550 135c004a 0a000004 e4d6c001 e35c0044  
    41743560 135c004a 02477004 0a000000 e4d6c001  
    41743570 e35c0000 0affffd2 e35c0044 135c004a  
    41743580 0a000002 e497c004 e488c004 eafffff6  
    41743590 e2888007 e497c004 e3c88007 e4972004  
    417435a0 e488c004 e4882004 eaffffef 00000000  
aldenml commented 7 years ago

do you have any other report with more information in the stacktrace?

proninyaroslav commented 7 years ago

Here are some of them, they maybe useful:

Build fingerprint: 'samsung/santos103gxx/santos103g:4.4.2/KOT49H/P5200XXUBNK1:user/release-keys'
Revision: '0'
pid: 14624, tid: 14624, name: rentTaskService  >>> org.proninyaroslav.libretorrent:TorrentTaskService <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 000001c8
    eax 00000000  ebx 70000005  ecx 00000e27  edx 00000071
    esi 00000001  edi bfb8ad7c
    xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000  xss 0000007b
    eip 65949f3b  ebp bfb8adb4  esp bfb8ad58  flags 00210206

backtrace:
    #00  pc 001c2f3b  /data/app-lib/org.proninyaroslav.libretorrent-1/libjlibtorrent.so
    #01  pc 00083335  /system/lib/libdvm.so
    #02  pc 00002f1f  <unknown>
    #03  pc 000e06dc  /system/lib/libdvm.so
    #04  pc 00000118  /dev/ashmem/dalvik-jit-code-cache (deleted)
    #05  pc 00098c80  /system/lib/libdvm.so
    #06  pc 000948c1  /system/lib/libdvm.so
    #07  pc 00113798  /system/lib/libdvm.so
    #08  pc 00126c69  /system/lib/libdvm.so
    #09  pc 00237c79  /system/lib/libdvm.so
    #10  pc 00008e9b  <unknown>
    #11  pc 00098c80  /system/lib/libdvm.so
    #12  pc 000948c1  /system/lib/libdvm.so
    #13  pc 001144ae  /system/lib/libdvm.so
    #14  pc 000d47ad  /system/lib/libdvm.so
    #15  pc 000624ba  /system/lib/libandroid_runtime.so
    #16  pc 000647a4  /system/lib/libandroid_runtime.so
    #17  pc 00000f14  /system/bin/app_process
    #18  pc 0001dd4a  /system/lib/libc.so
    #19  pc 00001206  /system/bin/app_process
Build fingerprint: 'google/angler/angler:7.1.1/NMF26F/3425388:user/release-keys'
Revision: '0'
ABI: 'arm64'
pid: 32118, tid: 32118, name: rentTaskService  >>> org.proninyaroslav.libretorrent:TorrentTaskService <<<
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x54
    x0   0000007373c3e000  x1   0000007fd307d1f4  x2   0000007356a8e718  x3   0000007fd307d1f8
    x4   0000000000000284  x5   0000000071735da9  x6   8080808080808080  x7   fefefefefefefeff
    x8   0000000000000050  x9   0000000000000000  x10  0000000000430000  x11  000000000020001c
    x12  00000073736aa8d0  x13  0000000000000000  x14  00000073736aa984  x15  0000000000000000
    x16  0000007fd307d1f8  x17  0000000000e00c7e  x18  0000000000000000  x19  0000007373c95a00
    x20  00000073582f846c  x21  00000000131619a0  x22  0000000013159710  x23  0000000000000284
    x24  0000000012c9a0a0  x25  0000000000000285  x26  0000000000000284  x27  0000000012c9a0d0
    x28  0000000012cc55b0  x29  00000000131619a0  x30  0000007358cc3f4c
    sp   0000007fd307d1e0  pc   00000073582f8484  pstate 0000000020000000

backtrace:
    #00 pc 000000000020e484  /data/app/org.proninyaroslav.libretorrent-1/lib/arm64/libjlibtorrent.so (Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_bitfield_1get_1bit+24)
    #01 pc 000000000067af48  /data/app/org.proninyaroslav.libretorrent-1/oat/arm64/base.odex (offset 0x5fc000)
aldenml commented 7 years ago

I suspect that you are calling get_bit in a bitfield that have no data inside. Could you point me to the code where you are using this method?

aldenml commented 7 years ago

I suspect that you are calling get_bit in a bitfield that have no data inside. Could you point me to the code where you are using this method?

proninyaroslav commented 7 years ago

Apparently getPieces() returns null.

private double calcRelevance(peer_info peer, TorrentStatus torrentStatus)
    {
        bitfield allPieces = torrentStatus.pieces().swig();
        bitfield peerPieces = peer.getPieces();

        int remoteHaves = 0;
        int localMissing = 0;

        for (int i = 0; i < allPieces.size(); i++) {
            if (!allPieces.get_bit(i)) {
                ++localMissing;

                if (peerPieces.get_bit(i)) {
                    ++remoteHaves;
                }
            }
        }

        double relevance = 0.0;

        if (localMissing != 0) {
            relevance = (double) remoteHaves / (double) localMissing;
        }

        return relevance;
    }
aldenml commented 7 years ago

Hi @proninyaroslav, I added a test https://github.com/frostwire/frostwire-jlibtorrent/commit/6c5f037f5b571154e8bcd97f43efedc73eb07a3f and I can't replicate the issue.

I point out that you need to pass the flag QUERY_PIECES to actually get the field populated and it's expensive. I looked also at libretorrent and I see a code like this:

piece_index_bitfield allPieces = torrentStatus.pieces().swig();
piece_index_bitfield peerPieces = peer.getPieces();

Remember that the more you work with swig() objects, the more careful you need to be with the lifetime of this objects and parents.

Feel free to reopen if you can provide a more concrete example or tweak the unit test to make it fail.