aous72 / OpenJPH

Open-source implementation of JPEG2000 Part-15 (or JPH or HTJ2K)
BSD 2-Clause "Simplified" License
201 stars 47 forks source link

Have crash in armeabi-v7a ( 32-bit ARM-based CPUs) #76

Closed ngoluuduythai closed 1 year ago

ngoluuduythai commented 3 years ago

I run OpenJPH lib in android, the code is work good for "x86", "x86_64", "arm64-v8a". But I have crashed when running it in . a Samsung j7 prime (armeabi-v7).

09-29 15:46:34.192 10804 28443 28443 F libc    : Fatal signal 7 (SIGBUS), code 1, fault addr 0xc70007ef in tid 28443 (com.openjph), pid 28443 (com.openjph)
09-29 15:46:34.276 10804 28489 28489 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
09-29 15:46:34.276 10804 28489 28489 F DEBUG   : Build fingerprint: 'samsung/on7xeltedd/on7xelte:8.1.0/M1AJQ/G610FDXS1CTE1:user/release-keys'
09-29 15:46:34.276 10804 28489 28489 F DEBUG   : Revision: '3'
09-29 15:46:34.276 10804 28489 28489 F DEBUG   : ABI: 'arm'
09-29 15:46:34.276 10804 28489 28489 F DEBUG   : pid: 28443, tid: 28443, name: com.openjph  >>> com.openjph <<<
09-29 15:46:34.276 10804 28489 28489 F DEBUG   : signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xc70007ef
09-29 15:46:34.276 10804 28489 28489 F DEBUG   :     r0 c70007eb  r1 c70007fb  r2 c72562ac  r3 00000001
09-29 15:46:34.276 10804 28489 28489 F DEBUG   :     r4 c80566d0  r5 00000000  r6 c7000000  r7 ffb56bb8
09-29 15:46:34.276 10804 28489 28489 F DEBUG   :     r8 c72562ac  r9 000004c4  sl 000004d4  fp 0006b729
09-29 15:46:34.277 10804 28489 28489 F DEBUG   :     ip c78949a4  sp ffb56ba0  lr c787e529  pc c788319a  cpsr 60070030
09-29 15:46:34.279 10804 28489 28489 F DEBUG   : 
09-29 15:46:34.279 10804 28489 28489 F DEBUG   : backtrace:
09-29 15:46:34.279 10804 28489 28489 F DEBUG   :     #00 pc 0003119a  /data/app/com.openjph-xuFG3APog506_hRWqpzozA==/lib/arm/libojph.so (ojph::mem_elastic_allocator::get_buffer(int, ojph::coded_lists*&)+131)
09-29 15:46:34.279 10804 28489 28489 F DEBUG   :     #01 pc 0002c525  /data/app/com.openjph-xuFG3APog506_hRWqpzozA==/lib/arm/libojph.so (ojph::local::precinct::parse(int, int*, ojph::mem_elastic_allocator*, unsigned int&, ojph::infile_base*, bool)+1392)
09-29 15:46:34.279 10804 28489 28489 F DEBUG   :     #02 pc 0002afc5  /data/app/com.openjph-xuFG3APog506_hRWqpzozA==/lib/arm/libojph.so (ojph::local::resolution::parse_one_precinct(unsigned int&, ojph::infile_base*)+54)
09-29 15:46:34.279 10804 28489 28489 F DEBUG   :     #03 pc 0002915f  /data/app/com.openjph-xuFG3APog506_hRWqpzozA==/lib/arm/libojph.so (ojph::local::tile::parse_tile_header(ojph::local::param_sot const&, ojph::infile_base*, unsigned long long const&)+618)
09-29 15:46:34.279 10804 28489 28489 F DEBUG   :     #04 pc 00026823  /data/app/com.openjph-xuFG3APog506_hRWqpzozA==/lib/arm/libojph.so (ojph::local::codestream::read()+918)
09-29 15:46:34.279 10804 28489 28489 F DEBUG   :     #05 pc 000301e5  /data/app/com.openjph-xuFG3APog506_hRWqpzozA==/lib/arm/libojph.so (ojph::htj2kdecompress::decode(unsigned char const*, unsigned int)+136)
09-29 15:46:34.279 10804 28489 28489 F DEBUG   :     #06 pc 000313c5  /data/app/com.openjph-xuFG3APog506_hRWqpzozA==/lib/arm/libojph.so (Java_com_ht2k_openjph_HT2KDecoder_decodeHT2KByteArray+64)
09-29 15:46:34.279 10804 28489 28489 F DEBUG   :     #07 pc 00011075  /data/app/com.openjph-xuFG3APog506_hRWqpzozA==/oat/arm/base.odex (offset 0x11000)

I also set DOJPH_DISABLE_INTEL_SIMD

set(CMAKE_CXX_FLAGS "-std=c++11 -O3 -fexceptions -DOJPH_DISABLE_INTEL_SIMD")

in my code

aous72 commented 3 years ago

signal 7 (SIGBUS), code 1 (BUS_ADRALN),

This means that OpenJPH is reading from an aligned address; for example, OpenJPH might be reading an integer from the address 0xc70007ef. The address 0xc70007ef has f at the end, which means only 1 byte can be read. An integer can only be read from 0xc70007ec or 0xc70007f0; notice the last address digit is a multiple of 4, the size of integer.

Intel/AMD has no problem with alignment, and Aarch64 also has no problem. In armv7, this can be enabled/disabled. Can you allow unaligned access?

I am not familiar with the platform, and I cannot test it. I used qemu, but this cannot check for alignment, and the code worked without issues.

Kind regards, Aous

ngoluuduythai commented 3 years ago

Thanks, @aous72, Your answer was very helpful for me. I will try to allow unaligned access. Best Regards, Thai

ngoluuduythai commented 3 years ago

I try to set the compiler to allow unaligned access but it still crashes (I try to add to the flag of compile -munaligned-access, -mno-unaligned-access ). And I put log more in the lib, I found crash happen in ojph_mem.cpp at line 115 [1] p = new (cur_store->data) coded_lists(needed_bytes); The crash doesn't happen with debug build. This happens with the release build and in seconds time it goes to this code with an even address like 0xc8b007ef.

10-05 21:06:15.328 10828 25349 25349 I testjni : ==== 170 coded_lists addr mode 4 = 0
10-05 21:06:15.328 10828 25349 25349 I testjni : ==== 170 (ui8*)this + sizeof(coded_lists) addr mode 4 = 0
10-05 21:06:15.328 10828 25349 25349 I testjni : ==== 174 coded_lists (ui8*)this address 0xc8b00010
10-05 21:06:15.328 10828 25349 25349 I testjni : ==== 174 coded_lists (ui8*)this size 4
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 174 coded_lists this->buf address 0xc8b00020
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 174 coded_lists this->buf 
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 132 p address 0xc8b00020
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 132 p val 
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 132 cur_store->data address af 0xc8b00010
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 132 cur_store->data val af 
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 136
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 137
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 141
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 145
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== parse_one_precinct
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== precinct::parse
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== parse_one_precinct
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== precinct::parse
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== parse_one_precinct
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== precinct::parse
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== elastic->get_buffer  cur_coded_list 16 
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== mem_elastic_allocator::get_buffer
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 107    needed_bytes 1220 
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 107    sizeof(coded_lists) 16 
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 107    extended_bytes 1236 
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 131
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 132 coded_lists needed_bytes 1220
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 132 cur_store->data address bf  0xc8b007ef
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 132 cur_store->data val  
10-05 21:06:15.329 10828 25349 25349 I testjni : ==== 132 stores_list size 16

With the debug build it can pass through it. And decode success. In this code, I found it will alternate between an even and an old address like this.

cur_store->data address bf  0xc7780010
cur_store->data address bf  0xc77807ef
cur_store->data address bf  0xc7780cc3
cur_store->data address bf  0xc7781124

@aous72 I want to ask, What is the difference between debug build and release build?. I guess in release build unaligned access happens with an event address. Best Regards, Thai

aous72 commented 3 years ago

Hi Thai,

It is hard for me to know from here what is wrong, but let's try to find it.

What is the difference between debug build and release build?.

This is a general question; you can find a lot of explanations for it if you do a search in google.
There is nothing special in OpenJPH between debug and release. Basically, debug mode does not employ any optimization; the generated machine code has a simple correspondence (or relationship) with the code; that is, there is some machine code for each line of C++. Variables in C++ are also assigned specific memory addresses or registers in machine code. Release, on the other hand, performs a lot of optimization; the relationship between machine code and C++ code is not simple. Some steps might be changed, skipped, or merged with other steps to make the code run faster. Sometimes, memory initialization is different between debug and release, and this is usually annoying to debug. Sometimes there is a smaller number of checks in Release. Also, asserts might be remove in Release, but that depends on a specific flag; I think NDEBUG or something like that. It is also possible that the compiler is buggy, but this is very unlikely.

The line 115 p = new (cur_store->data) coded_lists(needed_bytes); calls the constructor of stores_list structure. This structure is defined in lines 200-211 in ojph_mem.h

    struct stores_list
    {
      stores_list(ui32 chunk_size)
      {
        this->next_store = NULL;
        this->available = chunk_size - (ui32)sizeof(stores_list);
        this->data = (char*)this + sizeof(stores_list);
      }
      stores_list *next_store;
      ui32 available;
      char* data;
    };

Can you check sizeof(stores_list); the address of this in the line this->data = (char*)this + sizeof(stores_list); Also check line 110 of ojph_mem.cpp cur_store->next_store = (stores_list*)malloc(bytes); Check that cur_store->next_store is aligned.

The number 0xc8b007ef does not look correct, because it does not make sense to me.

Kind regards, Aous

ngoluuduythai commented 3 years ago

Thanks @aous72,

ngoluuduythai commented 3 years ago

This stores_list addr

10-06 10:42:57.295 10828 14296 14296 I testjni : ==== stores_list addr 0xc6200000
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== stores_list this->data addr 0xc620000c
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== stores_list size 12

I think when store_list go to this line. cur_store->data += extended_bytes; the addr will chance to an even addr to next time. Best Regards, Thai

ngoluuduythai commented 3 years ago

I put full log here

10-06 10:42:57.287  1000  2988  2988 W ResourceType: For resource 0x7f1411ab, entry index(4523) is beyond type entryCount(1788)
10-06 10:42:57.287 10828 14296 14323 I FA      : App measurement initialized, version: 42097
10-06 10:42:57.287 10828 14296 14323 I FA      : To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
10-06 10:42:57.287 10828 14296 14323 I FA      : To enable faster debug mode event logging run:
10-06 10:42:57.287 10828 14296 14323 I FA      :   adb shell setprop debug.firebase.analytics.app com.openjph
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== htj2kdecompress::decode 
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== 775 new_char 79 
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== 775 char_list[j] 79 with 0 
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== 775 new_char 81 
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== 775 char_list[j] 81 with 0 
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== 775 new_char 80 
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== 775 char_list[j] 80 with 0 
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== 775 char_list[j] 86 with 1 
10-06 10:42:57.293 10828 14296 14296 I testjni : ==== 775 char_list[j] 89 with 2 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 82 with 3 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 83 with 4 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 92 with 5 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 93 with 6 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 94 with 7 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 95 with 8 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 96 with 9 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 85 with 10 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 87 with 11 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 99 with 12 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 100 with 13 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 144 with 14 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 new_char 82 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 80 with 0 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 86 with 1 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 89 with 2 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 82 with 3 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 83 with 4 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 92 with 5 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 93 with 6 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 94 with 7 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 95 with 8 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 96 with 9 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 85 with 10 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 87 with 11 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 99 with 12 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 100 with 13 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 144 with 14 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 new_char 92 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 80 with 0 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 86 with 1 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 89 with 2 
10-06 10:42:57.294  1000  2988  2988 W ResourceType: For resource 0x7f1411ac, entry index(4524) is beyond type entryCount(1788)
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 82 with 3 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 83 with 4 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 92 with 5 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 93 with 6 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 94 with 7 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 95 with 8 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 96 with 9 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 85 with 10 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 87 with 11 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 99 with 12 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 100 with 13 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 144 with 14 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 new_char 100 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 80 with 0 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 86 with 1 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 89 with 2 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 82 with 3 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 83 with 4 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 92 with 5 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 93 with 6 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 94 with 7 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 95 with 8 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 96 with 9 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 85 with 10 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 87 with 11 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 99 with 12 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 100 with 13 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 char_list[j] 144 with 14 
10-06 10:42:57.294 10828 14296 14296 I testjni : ==== 775 new_char 144 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 80 with 0 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 86 with 1 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 89 with 2 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 82 with 3 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 83 with 4 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 92 with 5 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 93 with 6 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 94 with 7 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 95 with 8 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 96 with 9 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 85 with 10 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 87 with 11 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 99 with 12 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 100 with 13 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 144 with 14 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== codestream.read_headers
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== codestream.restrict_input_resolution
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== tile_start_location
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 948
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 1056
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 new_char 147 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 82 with 0 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 83 with 1 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 92 with 2 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 93 with 3 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 94 with 4 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 95 with 5 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 97 with 6 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 88 with 7 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 100 with 8 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 775 char_list[j] 147 with 9 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== marker_idx 9
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== sod_found
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== tiles
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== parse_one_precinct
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== precinct::parse
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== elastic->get_buffer  cur_coded_list 16 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== mem_elastic_allocator::get_buffer
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 107    needed_bytes 1999 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 107    sizeof(coded_lists) 16 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 107    extended_bytes 2015 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 114  bytes 1048576 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== 114  chunk_size 1048576 
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== stores_list addr 0xc6200000
10-06 10:42:57.295 10828 14296 14296 I testjni : ==== stores_list this->data addr 0xc620000c
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== stores_list size 12
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 131
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  coded_lists needed_bytes 1999
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  cur_store->data address bf  0xc620000c
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  cur_store->data val  
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  stores_list size 12
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 170 next_list 4
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 170 buf_size int 4
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 170 avail_size int 4
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 170 buf 4
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 170 coded_lists 16
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 170 coded_lists addr mode 4 = 0
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 170 (ui8*)this + sizeof(coded_lists) addr mode 4 = 0
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 174 coded_lists (ui8*)this address 0xc620000c
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 174 coded_lists (ui8*)this size 4
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 174 coded_lists this->buf address 0xc620001c
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 174 coded_lists this->buf 
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  p address 0xc620001c
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  p val 
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  cur_store->data address af 0xc620000c
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  cur_store->data val af 
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 136
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 137
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 141
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 145
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== parse_one_precinct
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== precinct::parse
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== parse_one_precinct
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== precinct::parse
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== parse_one_precinct
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== precinct::parse
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== elastic->get_buffer  cur_coded_list 16 
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== mem_elastic_allocator::get_buffer
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 107    needed_bytes 1220 
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 107    sizeof(coded_lists) 16 
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 107    extended_bytes 1236 
10-06 10:42:57.296 10828 14296 14296 I testjni : ==== 131
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  coded_lists needed_bytes 1220
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  cur_store->data address bf  0xc62007eb
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  cur_store->data val  
10-06 10:42:57.296 10828 14296 14296 I testjni : ====  stores_list size 12
10-06 10:42:57.297 10828 14296 14296 F libc    : Fatal signal 7 (SIGBUS), code 1, fault addr 0xc62007f3 in tid 14296 (com.openjph), pid 14296 (com.openjph)
10-06 10:42:57.306  1017  2708  2708 W keystore: ENTER remove operation from uid 10027
10-06 10:42:57.309  1017  2708  2708 I chatty  : uid=1017(keystore) /system/bin/keystore identical 1 line
10-06 10:42:57.314  1017  2708  2708 W keystore: ENTER remove operation from uid 10027
10-06 10:42:57.319 10828 14296 14323 I zygote  : Deoptimizing java.lang.Object c.b.a.b.f.b.w2.a(java.lang.Object) due to JIT inline cache
10-06 10:42:57.335 10027  9060  9086 I appr    : Provider GmsCore_OpenSSL not available
10-06 10:42:57.339 10015  4246 14221 W ResourceType: ResTable_typeSpec entry count inconsistent: given 1065, previously 1114
10-06 10:42:57.339 10015  4246 14221 W ResourceType: ResTable_typeSpec entry count inconsistent: given 4275, previously 4276
10-06 10:42:57.339 10015  4246 14221 W ResourceType: ResTable_typeSpec entry count inconsistent: given 28, previously 27
10-06 10:42:57.339 10015  4246 14221 W ResourceType: ResTable_typeSpec entry count inconsistent: given 166, previously 742
10-06 10:42:57.367 audit  2682  2682 E audit   : type=1400 audit(1633491777.361:956): avc:  denied  { search } for  pid=14376 comm="crash_dump32" name="com.google.android.gms" dev="dm-1" ino=397544 scontext=u:r:crash_dump:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SM-G610F_8.1.0_0007 audit_filtered
10-06 10:42:57.367 audit  2682  2682 E audit   : type=1300 audit(1633491777.361:956): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=ea8c2060 a2=20000 a3=0 items=0 ppid=1 pid=14376 auid=4294967295 uid=10828 gid=10828 euid=10828 suid=10828 fsuid=10828 egid=10828 sgid=10828 fsgid=10828 tty=(none) ses=4294967295 comm="crash_dump32" exe="/system/bin/crash_dump32" subj=u:r:crash_dump:s0:c512,c768 key=(null)
10-06 10:42:57.367 audit  2682  2682 E audit   : type=1327 audit(1633491777.361:956): proctitle=63726173685F64756D7033320031343239360031343337320031
10-06 10:42:57.377 10015  4246 14221 I Icing   : Usage reports ok 3, Failed Usage reports 2, indexed 2, rejected 0
10-06 10:42:57.386 10058  4370  4461 W ResourceType: ResTable_typeSpec entry count inconsistent: given 15, previously 26
10-06 10:42:57.387  1017  2708  2708 W keystore: ENTER remove operation from uid 10027
10-06 10:42:57.389  1017  2708  2708 I chatty  : uid=1017(keystore) /system/bin/keystore identical 1 line
10-06 10:42:57.391  1017  2708  2708 W keystore: ENTER remove operation from uid 10027
10-06 10:42:57.415 10058  4370  4461 W ResourceType: ResTable_typeSpec entry count inconsistent: given 15, previously 26
10-06 10:42:57.423 10058  4370  4461 W ResourceType: ResTable_typeSpec entry count inconsistent: given 2539, previously 2552
10-06 10:42:57.426 10058  4370  4461 W ResourceType: ResTable_typeSpec entry count inconsistent: given 312, previously 2034
10-06 10:42:57.448 10015  4246 14221 I GmsCoreXrpcWrapper: Returning a channel provider with trafficStatsTag=12803 trafficStatsUid=-1
10-06 10:42:57.460  1000  2988  3160 D WifiTrafficPoller: TrafficStats TxPkts=157190 RxPkts=275741 TxBytes=15352861 RxBytes=321521343 , Foreground uid=10828 pkgName=com.openjph txBytes=1949 rxBytes=5484
10-06 10:42:57.476 10015  4246 14221 I Icing   : Usage reports ok 0, Failed Usage reports 0, indexed 0, rejected 0
10-06 10:42:57.482  1000  2612  2612 I display : [PrimaryDisplay] [DYNAMIC_RECOMP] first frame after HWC_2_GLES
10-06 10:42:57.482  1000  2612  2612 I display : [PrimaryDisplay] [DYNAMIC_RECOMP] GLES_2_HWC by high FPS(5)
10-06 10:42:57.505 10015  4246 14221 I Icing   : Indexing com.google.android.gms-apps from com.google.android.gms
10-06 10:42:57.519 10828 14376 14376 I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
10-06 10:42:57.527  1058  2726  2726 I /system/bin/tombstoned: received crash request for pid 14296
10-06 10:42:57.542 10828 14376 14376 I crash_dump32: performing dump of process 14296 (target tid = 14296)
10-06 10:42:57.542 10828 14376 14376 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-06 10:42:57.542 10828 14376 14376 F DEBUG   : Build fingerprint: 'samsung/on7xeltedd/on7xelte:8.1.0/M1AJQ/G610FDXS1CTE1:user/release-keys'
10-06 10:42:57.542 10828 14376 14376 F DEBUG   : Revision: '3'
10-06 10:42:57.542 10828 14376 14376 F DEBUG   : ABI: 'arm'
10-06 10:42:57.542 10828 14376 14376 F DEBUG   : pid: 14296, tid: 14296, name: com.openjph  >>> com.openjph <<<
10-06 10:42:57.542 10828 14376 14376 F DEBUG   : signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xc62007f3
10-06 10:42:57.543 10828 14376 14376 F DEBUG   :     r0 c62007eb  r1 000004c4  r2 d6999441  r3 0000003d
10-06 10:42:57.543 10828 14376 14376 F DEBUG   :     r4 d7f37310  r5 e6dd84c9  r6 c69ece73  r7 ffd50bb8
10-06 10:42:57.543 10828 14376 14376 F DEBUG   :     r8 c62007eb  r9 000004c4  sl 000004d4  fp e6dd84c9
10-06 10:42:57.543 10828 14376 14376 F DEBUG   :     ip c6a1be10  sp ffd50ba8  lr c6a0a345  pc c6a0a49e  cpsr 600e0030
10-06 10:42:57.545 10828 14376 14376 F DEBUG   : 
10-06 10:42:57.545 10828 14376 14376 F DEBUG   : backtrace:
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #00 pc 0003249e  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/lib/arm/libojph.so (ojph::coded_lists::coded_lists(int)+9)
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #01 pc 00032341  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/lib/arm/libojph.so (ojph::mem_elastic_allocator::get_buffer(int, ojph::coded_lists*&)+276)
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #02 pc 0002d021  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/lib/arm/libojph.so (ojph::local::precinct::parse(int, int*, ojph::mem_elastic_allocator*, unsigned int&, ojph::infile_base*, bool)+1432)
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #03 pc 0002ba8f  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/lib/arm/libojph.so (ojph::local::resolution::parse_one_precinct(unsigned int&, ojph::infile_base*)+70)
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #04 pc 00029c17  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/lib/arm/libojph.so (ojph::local::tile::parse_tile_header(ojph::local::param_sot const&, ojph::infile_base*, unsigned long long const&)+618)
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #05 pc 000272e9  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/lib/arm/libojph.so (ojph::local::codestream::read()+1636)
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #06 pc 00030d1b  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/lib/arm/libojph.so (ojph::htj2kdecompress::decode(unsigned char const*, unsigned int)+150)
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #07 pc 00032799  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/lib/arm/libojph.so (Java_com_ht2k_openjph_HT2KDecoder_decodeHT2KByteArray+64)
10-06 10:42:57.545 10828 14376 14376 F DEBUG   :     #08 pc 00010075  /data/app/com.openjph-CuC0VyfKt2z1PBL73QLHBw==/oat/arm/base.odex (offset 0x10000)
10-06 10:42:57.569 10015  4246 14221 I Icing   : Indexing done com.google.android.gms-apps
10-06 10:42:57.585  1250 14356 14356 D KnoxUsageDB: getInstance - KnoxUsageDBHelper
aous72 commented 3 years ago

I think when store_list go to this line. cur_store->data += extended_bytes; the addr will chance to an even addr to next time.

It is still not clear to me what is going on, but if you believe that this is the problem, we can fix it by extending extended_bytes to make it a multiple of 4. You might be correct.

Write ui32 extended_bytes = ((needed_bytes + 3) & ~3) + (ui32)sizeof(coded_lists); instead of ui32 extended_bytes = needed_bytes + (ui32)sizeof(coded_lists);

We know that coded_list size is a multiple of 4.

See if that works.

Kind regards, Aous.

ngoluuduythai commented 3 years ago

Thanks, @aous72, I will try with it. Best Regards, Thai

ngoluuduythai commented 3 years ago

I pass through it. And crash in another place, it will check it @aous72

10-06 11:48:37.606 10828 26083 26083 I testjni : ==== 775 new_char 217 
10-06 11:48:37.606 10828 26083 26083 I testjni : ==== 775 char_list[j] 144 with 0 
10-06 11:48:37.606 10828 26083 26083 I testjni : ==== 775 char_list[j] 217 with 1 
10-06 11:48:37.606 10828 26083 26083 I testjni : ==== marker_idx 1
10-06 11:48:37.606 10828 26083 26083 I testjni : ==== 1145
10-06 11:48:37.606 10828 26083 26083 I testjni : ==== codestream.create
10-06 11:48:37.606 10828 26083 26083 I testjni : ==== codestream.set_planar
10-06 11:48:37.606 10828 26083 26083 I testjni : ==== height width
10-06 11:48:37.606 10828 26083 26083 I testjni : ==== mem_outfile.write
10-06 11:48:37.607 10828 26083 26083 F libc    : Fatal signal 7 (SIGBUS), code 1, fault addr 0xc60807e3 in tid 26083 (com.openjph), pid 26083 (com.openjph)
10-06 11:48:37.657 audit  2682  2682 E audit   : type=1400 audit(1633495717.642:1097): avc:  denied  { search } for  pid=26120 comm="crash_dump32" name="com.google.android.gms" dev="dm-1" ino=397544 scontext=u:r:crash_dump:s0:c512,c768 tcontext=u:object_r:app_data_file:s0:c512,c768 tclass=dir permissive=0 SEPF_SM-G610F_8.1.0_0007 audit_filtered
10-06 11:48:37.657 audit  2682  2682 E audit   : type=1300 audit(1633495717.642:1097): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=eacc2060 a2=20000 a3=0 items=0 ppid=1 pid=26120 auid=4294967295 uid=10828 gid=10828 euid=10828 suid=10828 fsuid=10828 egid=10828 sgid=10828 fsgid=10828 tty=(none) ses=4294967295 comm="crash_dump32" exe="/system/bin/crash_dump32" subj=u:r:crash_dump:s0:c512,c768 key=(null)
10-06 11:48:37.657 audit  2682  2682 E audit   : type=1327 audit(1633495717.642:1097): proctitle=63726173685F64756D7033320032363038330032363131360031
10-06 11:48:37.679 10828 26120 26120 I crash_dump32: obtaining output fd from tombstoned, type: kDebuggerdTombstone
10-06 11:48:37.679  1058  2726  2726 I /system/bin/tombstoned: received crash request for pid 26083
10-06 11:48:37.681 10828 26120 26120 I crash_dump32: performing dump of process 26083 (target tid = 26083)
10-06 11:48:37.682 10828 26120 26120 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
10-06 11:48:37.682 10828 26120 26120 F DEBUG   : Build fingerprint: 'samsung/on7xeltedd/on7xelte:8.1.0/M1AJQ/G610FDXS1CTE1:user/release-keys'
10-06 11:48:37.682 10828 26120 26120 F DEBUG   : Revision: '3'
10-06 11:48:37.682 10828 26120 26120 F DEBUG   : ABI: 'arm'
10-06 11:48:37.682 10828 26120 26120 F DEBUG   : pid: 26083, tid: 26083, name: com.openjph  >>> com.openjph <<<
10-06 11:48:37.682 10828 26120 26120 F DEBUG   : signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xc60807e3
10-06 11:48:37.682 10828 26120 26120 F DEBUG   :     r0 ffffffff  r1 00000000  r2 c60807e3  r3 c60807e3
10-06 11:48:37.682 10828 26120 26120 F DEBUG   :     r4 ffd50848  r5 c60807e3  r6 000007bf  r7 ffd50770
10-06 11:48:37.682 10828 26120 26120 F DEBUG   :     r8 00000000  r9 000001af  sl 00000020  fp 000001b3
10-06 11:48:37.682 10828 26120 26120 F DEBUG   :     ip c6805ab0  sp ffd50750  lr c67e4de5  pc c67e6e46  cpsr 600e0030
10-06 11:48:37.685 10828 26120 26120 F DEBUG   : 
10-06 11:48:37.685 10828 26120 26120 F DEBUG   : backtrace:
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #00 pc 00024e46  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (_ZN4ojph5local9frwd_readILi0EEEvPNS0_11frwd_structE+23)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #01 pc 00022de1  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::ojph_decode_codeblock(unsigned char*, int*, int, int, int, int, int, int, int)+428)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #02 pc 0002d635  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::codeblock::decode()+80)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #03 pc 0002c1fb  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::subband::pull_line()+202)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #04 pc 0002b587  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::resolution::pull_line()+98)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #05 pc 0002b587  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::resolution::pull_line()+98)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #06 pc 0002b587  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::resolution::pull_line()+98)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #07 pc 0002b587  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::resolution::pull_line()+98)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #08 pc 0002b587  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::resolution::pull_line()+98)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #09 pc 0002a4b5  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::tile::pull(ojph::line_buf*, int)+228)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #10 pc 0002749d  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::local::codestream::pull(int&)+42)
10-06 11:48:37.685 10828 26120 26120 F DEBUG   :     #11 pc 00030ddb  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (ojph::htj2kdecompress::decode(unsigned char const*, unsigned int)+342)
10-06 11:48:37.686 10828 26120 26120 F DEBUG   :     #12 pc 0003279d  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/lib/arm/libojph.so (Java_com_ht2k_openjph_HT2KDecoder_decodeHT2KByteArray+64)
10-06 11:48:37.686 10828 26120 26120 F DEBUG   :     #13 pc 00010075  /data/app/com.openjph-rfeWMYem5-JX4h-5UBpwKg==/oat/arm/base.odex (offset 0x10000)
10-06 11:48:37.758 audit  2682  2682 E audit   : type=1400 audit(1633495717.742:1098): avc:  denied  { read } for  pid=26119 comm="Thread-88" name="mem_profile" dev="debugfs" ino=61113 scontext=u:r:priv_app:s0:c512,c768 tcontext=u:object_r:sec_debugfs:s0 tclass=file permissive=0 SEPF_SM-G610F_8.1.0_0007 unfiltered
10-06 11:48:37.758 audit  2682  2682 E audit   : type=1300 audit(1633495717.742:1098): arch=40000028 syscall=322 per=8 success=no exit=-13 a0=ffffff9c a1=b98ae0b0 a2=20000 a3=0 items=0 ppid=2695 pid=26119 auid=4294967295 uid=10015 gid=10015 euid=10015 suid=10015 fsuid=10015 egid=10015 sgid=10015 fsgid=10015 tty=(none) ses=4294967295 comm="Thread-88" exe="/system/bin/app_process32" subj=u:r:priv_app:s0:c512,c768 key=(null)
10-06 11:48:37.760  1000  2988  3008 D SecurityLogAgent:SEDenialService: Got Modify Event and sending Denial Intent for audit.log / "com.google.android.gms.unstable"

Best Regards, Thai

aous72 commented 3 years ago

Hi Thai,

When I wrote OpenJPH, I did not care about alignment, because I could not test it.
Intel does not care, and I think I get the same performance for aligned or unaligned.

There can be many places with this problem. signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 0xc60807e3

mem_outfile.write has only memcpy(this->cur_ptr, ptr, size); which I think should work.

Let me know how to help.

Kind regards, Aous

ngoluuduythai commented 3 years ago

Sorry for my late reply @aous72 , The code goes far than mem_outfile, the log show it goes through it. So I am add more logs And found it is stopped in ojph_decode_codeblock.

10-06 14:21:29.230 10829 16897 16897 I testjni : ==== void codeblock::decode 
10-06 14:21:29.230 10829 16897 16897 I testjni : ==== codeblock::decode coded_cb 0xc4255ef8
10-06 14:21:29.230 10829 16897 16897 I testjni : ==== codeblock::decode coded_cb->next_coded 0xc400000c
10-06 14:21:29.230 10829 16897 16897 I testjni : ==== codeblock::decode coded_cb->next_coded->buf 0xc400001c
10-06 14:21:29.230 10829 16897 16897 I testjni : ==== ojph_decode_codeblock 705 
10-06 14:21:29.231 10829 16897 16897 I testjni : ==== ojph_decode_codeblock 737 
10-06 14:21:29.231 10829 16897 16897 F libc    : Fatal signal 7 (SIGBUS), code 1, fault addr 0xc40007e3 in tid 16897 (com.openjph), pid 16897 (com.openjph)

The code stop before 729 lines in this:

      //init mel
      mel_struct mel;
      mel_init(&mel, coded_data, lcup, scup);
      rev_struct vlc;
      rev_init(&vlc, coded_data, lcup, scup);
      frwd_struct magsgn;
      frwd_init<0xFF>(&magsgn, coded_data, lcup - scup);
      frwd_struct sigprop;
      frwd_init<0>(&sigprop, coded_data + lengths1, lengths2);
      rev_struct magref;

I found the coded_data have an even address. I think the even addr come from this.

                  int cbx0 = ojph_max(tbx0, x_lower_bound + i * nominal.w);
            int cbx1 = ojph_min(tbx1, x_lower_bound + (i + 1) * nominal.w);
            cb_size.w = cbx1 - cbx0;
            blocks[i].recreate(cb_size,
                               coded_cbs + i + cur_cb_row * num_blocks.w);
            blocks[i].decode();

Best Regards, Thai

aous72 commented 3 years ago

Hi Thai,

An idea comes to my mind.

You said no problem in debug -- I assume you using cmake -DCMAKE_BUILD_TYPE=Debug The crash occurs in Release, which you obtain using cmake -DCMAKE_BUILD_TYPE=Release

Maybe we can fix Release by adding a flag. We get this flag from Debug.

Use make VERBOSE=1 or make -n to see complete make command. Look at the flags and see if there is any align or nonalign in them.

Kind regards, Aous.