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

Inappropriate method used to read string-type field values #1

Open
chaoslawful opened this issue Sep 19, 2014 · 0 comments
Open

Inappropriate method used to read string-type field values #1

chaoslawful opened this issue Sep 19, 2014 · 0 comments

Comments

@chaoslawful
Copy link

com.g414.haildb.TupleStorage.loadString used getString() to convert JNA pointer to Java string like this:

        return HailDB.ib_col_get_value(tupl.tupl, index).getString(0);

The method getString() assumed that every string buffer read from InnoDB is null-ended, which holds for string values written by com.g414.haildb.TupleStorage.storeString but not for real InnoDB databases. So when I use the package to parse a InnoDB backup data file, there are always unexpected trailing characters beyond the real data.

I wonder if TupleStorage.loadString could use getByteArray() instead of getString() to read exactly the same size of string data as field length specified, like the following code snippets doing:

        try {
            String res = new String(HailDB.ib_col_get_value(tupl.tupl, index).getByteArray(0, len), "utf-8");
            return res;
        } catch (UnsupportedEncodingException e) {
            return "";
        }

Of course TupleStorage.storeString also need to be changed to stop writing a extra null if this modification is made. By doing this, this project could be used to correctly parse offline MySQL InnoDB backups instead of just as a private storage engine.

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