Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in reading an extention #9

Open
amirshamaei opened this issue Dec 11, 2020 · 0 comments
Open

Exception in reading an extention #9

amirshamaei opened this issue Dec 11, 2020 · 0 comments

Comments

@amirshamaei
Copy link

amirshamaei commented Dec 11, 2020

Hi @cabeen
I hope you are well, I got an error when I wanted to read a nifti file that had a .json extension. It may be my misunderstanding of the format.

 while (start_addr < (int) ds.vox_offset)
            {
                int[] size_code = new int[2];
                size_code[0] = di.readInt();
                size_code[1] = di.readInt();

                int nb = size_code[0] - NiftiHeader.EXT_KEY_SIZE;
                byte[] eblob = new byte[nb];
                di.readFully(eblob, 0, nb);
                ds.extension_blobs.add(eblob);
                ds.extensions_list.add(size_code);
                start_addr += (size_code[0]);
                if (start_addr > (int) ds.vox_offset)
                    throw new IOException("Error: Data  for extension " + (ds.extensions_list.size())
                            + " appears to overrun start of image data.");
            }

let's assume we have a JSON file (157 bytes) and 8 bytes for extension keys; when it reaches to end; the start_addr is 509, so It starts again and reads the first 8 bytes which may be wrong.
I think if it checks the size of the rest bytes, it could be solved. like this:

if(((int) ds.vox_offset - start_addr)<16)
                    break;

Kind regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant