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

Native crash: input is not valid Modified UTF-8 #164

Closed gjedeer closed 7 years ago

gjedeer commented 7 years ago

Looks like a similar issue to https://github.com/frostwire/frostwire-jlibtorrent/issues/144 - this time, the same thing happens in FileStorage.fileName().

05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470] JNI DETECTED ERROR IN APPLICATION: input is not valid Modified UTF-8: illegal start byte 0xb8
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]     string: '��dp'
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]     input: '<0xb8> 0xf3 0x64 0x70'
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]     in call to NewStringUTF
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]     from java.lang.String com.frostwire.jlibtorrent.swig.libtorrent_jni.string_view_to_string(long, com.frostwire.jlibtorrent.swig.string_view)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470] "main" prio=5 tid=1 Runnable
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   | group="main" sCount=0 dsCount=0 obj=0x74b62688 self=0x42c84400
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   | sysTid=1387 nice=-10 cgrp=default sched=0/0 handle=0x4017f534
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   | state=R schedstat=( 1675387167 218343840 1396 ) utm=150 stm=17 core=2 HZ=100
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   | stack=0xbe796000-0xbe798000 stackSize=8MB
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   | held mutexes= "mutator lock"(shared held)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #00 pc 00351b41  /system/lib/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+128)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #01 pc 00332139  /system/lib/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMap+304)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #02 pc 0023a3f3  /system/lib/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+846)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #03 pc 0023a92b  /system/lib/libart.so (_ZN3art9JavaVMExt9JniAbortVEPKcS2_St9__va_list+58)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #04 pc 000caccb  /system/lib/libart.so (_ZN3art11ScopedCheck6AbortFEPKcz+42)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #05 pc 000cb64f  /system/lib/libart.so (_ZN3art11ScopedCheck14CheckUtfStringEPKcb+870)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #06 pc 000cac41  /system/lib/libart.so (_ZN3art11ScopedCheck17CheckNonHeapValueEcNS_12JniValueTypeE+108)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #07 pc 000c9937  /system/lib/libart.so (_ZN3art11ScopedCheck22CheckPossibleHeapValueERNS_18ScopedObjectAccessEcNS_12JniValueTypeE+130)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #08 pc 000c8da1  /system/lib/libart.so (_ZN3art11ScopedCheck5CheckERNS_18ScopedObjectAccessEbPKcPNS_12JniValueTypeE+800)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #09 pc 000c4d27  /system/lib/libart.so (_ZN3art8CheckJNI12NewStringUTFEP7_JNIEnvPKc+446)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #10 pc 001ee394  /mnt/expand/c5a05ef3-050f-4d41-8db7-c0ab89bdfd4d/app/com.github.funkyg.funkytunes-1/lib/arm/libjlibtorrent.so (Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_string_1view_1to_1string+128)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   native: #11 pc 00092b39  /mnt/expand/c5a05ef3-050f-4d41-8db7-c0ab89bdfd4d/app/com.github.funkyg.funkytunes-1/oat/arm/base.odex (Java_com_frostwire_jlibtorrent_swig_libtorrent_1jni_string_1view_1to_1string__JLcom_frostwire_jlibtorrent_swig_string_1view_2+116)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   at com.frostwire.jlibtorrent.swig.libtorrent_jni.string_view_to_string(Native method)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   at com.frostwire.jlibtorrent.swig.string_view.to_string(string_view.java:39)
05-30 21:52:36.655 F/art     (1387): art/runtime/java_vm_ext.cc:470]   at com.frostwire.jlibtorrent.FileStorage.fileName(FileStorage.java:351)
aldenml commented 7 years ago

Thanks for reporting this, I will take a look

aldenml commented 7 years ago

Hi @gjedeer, the issue is fixed with https://github.com/frostwire/frostwire-jlibtorrent/commit/186221eb15e2c393a34ef5810cb3cbb6a6c1c7b9.

Now you will get the default replacement character defined by the java framework (and not an unexpected exception or crash). If you want to get to the low level in order to manually decode invalid UTF-8 characters in the torrent file, you can go to the native .swig() object and get the byte[]. But remember, this is only for UI display, there is still UTF-8 decoding at the OS level for actual file system creation of files, and the characters there could be different, android OS does not support another encoding iirc.

1.2.0.9-RC4 is out for testing

gjedeer commented 7 years ago

Thank you @aldenml !