{"action":"created","issue":{"url":"https://api.github.com/repos/uclouvain/openjpeg/issues/518","labels_url":"https://api.github.com/repos/uclouvain/openjpeg/issues/518/labels{/name}","comments_url":"https://api.github.com/repos/uclouvain/openjpeg/issues/518/comments","events_url":"https://api.github.com/repos/uclouvain/openjpeg/issues/518/events","html_url":"https://github.com/uclouvain/openjpeg/issues/518","id":90807796,"number":518,"title":"Bigendian: opj_compress + opj_decompress fails","user":{"login":"manisandro","id":1298852,"avatar_url":"https://avatars.githubusercontent.com/u/1298852?v=3","gravatar_id":"","url":"https://api.github.com/users/manisandro","html_url":"https://github.com/manisandro","followers_url":"https://api.github.com/users/manisandro/followers","following_url":"https://api.github.com/users/manisandro/following{/other_user}","gists_url":"https://api.github.com/users/manisandro/gists{/gist_id}","starred_url":"https://api.github.com/users/manisandro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/manisandro/subscriptions","organizations_url":"https://api.github.com/users/manisandro/orgs","repos_url":"https://api.github.com/users/manisandro/repos","events_url":"https://api.github.com/users/manisandro/events{/privacy}","received_events_url":"https://api.github.com/users/manisandro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-06-24T23:44:49Z","updated_at":"2015-07-03T15:59:33Z","closed_at":null,"body":"On bigendian, converting some image to j2k and decompressing it again results in failure, i.e.:\r\n\r\n    $ wget http://people.sc.fsu.edu/~jburkardt/data/ppma/star_field.ascii.ppm\r\n    \r\n    $ opj2_compress -i star_field.ascii.ppm -o test.j2k -q 30,40,50\r\n    [INFO] tile number 1 / 1\r\n    Generated outfile test.j2k\r\n    \r\n    $ opj2_decompress -i test.j2k -o test.ppm\r\n    [INFO] Start to read j2k main header (0).\r\n    [ERROR] Prevent buffer overflow (x1: 671090818, y1: 671090818)\r\n    [ERROR] Marker handler function failed to read the marker segment\r\n    ERROR -> opj_decompress: failed to read the header\r\n\r\nA quick scan through the codebase reveals for instance in `convert.c` portions of code such as\r\n\r\n                union { signed short val; signed char vals[2]; } uc16;\r\n                mask = (1 << image->comps[compno].prec) - 1;\r\n                ptr = image->comps[compno].data;\r\n                for (line = 0; line < h; line++) {\r\n                    for(row = 0; row < w; row++)\t{\r\n                        curr = *ptr;\r\n                        if(curr > 32767 ) curr = 32767; else if( curr < -32768) curr = -32768;\r\n                        uc16.val = (signed short)(curr & mask);\r\n                        res = fwrite(uc16.vals, 1, 2, rawFile);\r\n                        if( res < 2 ) {\r\n                            fprintf(stderr, \"failed to write 2 byte for %s\\n\", outfile);\r\n                            goto fin;\r\n                        }\r\n                        ptr++;\r\n                    }\r\n                }\r\n\r\nwhich likely produce wrong results on bigendian."},"comment":{"url":"https://api.github.com/repos/uclouvain/openjpeg/issues/comments/118380781","html_url":"https://github.com/uclouvain/openjpeg/issues/518#issuecomment-118380781","issue_url":"https://api.github.com/repos/uclouvain/openjpeg/issues/518","id":118380781,"user":{"login":"detonin","id":429904,"avatar_url":"https://avatars.githubusercontent.com/u/429904?v=3","gravatar_id":"","url":"https://api.github.com/users/detonin","html_url":"https://github.com/detonin","followers_url":"https://api.github.com/users/detonin/followers","following_url":"https://api.github.com/users/detonin/following{/other_user}","gists_url":"https://api.github.com/users/detonin/gists{/gist_id}","starred_url":"https://api.github.com/users/detonin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/detonin/subscriptions","organizations_url":"https://api.github.com/users/detonin/orgs","repos_url":"https://api.github.com/users/detonin/repos","events_url":"https://api.github.com/users/detonin/events{/privacy}","received_events_url":"https://api.github.com/users/detonin/received_events","type":"User","site_admin":false},"created_at":"2015-07-03T15:59:33Z","updated_at":"2015-07-03T15:59:33Z","body":"@szukw000 PR is indeed the preferred way to submit patches (pasting them here does not work as comments here support mardown language). There is a learning curve indeed but it's *really* worthwile. Thanks."}}