#1255 cannot attach text tables (CSV files) with absolute path

current-release
closed-fixed
1
2014-08-13
2012-09-13
Anonymous
No

Hi there

I reported bug ID 3535299 against 2.2.6 on June 14. You reported the bug as fixed in 2.2.9 - thanks for paying attention to the bug report! However, I just upgraded to 2.2.9 and I still get the same error as I reported in 3535299. (I just copied the stack trace from bug report 3535299):

java.sql.SQLException: bad TEXT table source file - line number: 0 org.hsqldb.HsqlException: file input/output erroropenning file: java.io.FileNotFoundException: /tmp/2012-06-14T20-32-01.594+0200/meta/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv (No such file or directory) error: /tmp/2012-06-14T20-32-01.594+0200/meta/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv in statement [SET TABLE "TXN:zaviation/branches/5.8".T_TEXT SOURCE '/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv;ignore_first=true;fs=\semi;encoding=Cp1252' DESC]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.fetchResult(Unknown Source)
at org.hsqldb.jdbc.JDBCStatement.execute(Unknown Source)
at consor.tool.delta.helper.HsqldbHelper.executeNoCatch(HsqldbHelper.java:92)
at consor.tool.metadata.data.DataFileManager.attachTextTableSource(DataFileManager.java:139)
... 8 more
Caused by: org.hsqldb.HsqlException: bad TEXT table source file - line number: 0 org.hsqldb.HsqlException: file input/output erroropenning file: java.io.FileNotFoundException: /tmp/2012-06-14T20-32-01.594+0200/meta/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv (No such file or directory) error: /tmp/2012-06-14T20-32-01.594+0200/meta/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.TextTable.connect(Unknown Source)
at org.hsqldb.TextTable.openCache(Unknown Source)
at org.hsqldb.TextTable.setDataSource(Unknown Source)
at org.hsqldb.StatementCommand.getResult(Unknown Source)
at org.hsqldb.StatementCommand.execute(Unknown Source)
at org.hsqldb.Session.executeCompiledStatement(Unknown Source)
at org.hsqldb.Session.executeDirectStatement(Unknown Source)
at org.hsqldb.Session.execute(Unknown Source)
... 12 more
Caused by: org.hsqldb.HsqlException: file input/output erroropenning file: java.io.FileNotFoundException: /tmp/2012-06-14T20-32-01.594+0200/meta/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv (No such file or directory) error: /tmp/2012-06-14T20-32-01.594+0200/meta/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv
at org.hsqldb.error.Error.error(Unknown Source)
at org.hsqldb.persist.TextCache.open(Unknown Source)
at org.hsqldb.persist.Logger.openTextFilePersistence(Unknown Source)
... 20 more
Caused by: java.io.FileNotFoundException: /tmp/2012-06-14T20-32-01.594+0200/meta/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv (No such file or directory)
at java.io.RandomAccessFile.open(Native Method)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:98)
at org.hsqldb.persist.ScaledRAFile.<init>(Unknown Source)
at org.hsqldb.persist.ScaledRAFile.newScaledRAFile(Unknown Source)
... 22 more

Please note that the root cause is a FileNotFoundException, complaining that file
"/tmp/2012-06-14T20-32-01.594+0200/meta/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv"

does not exist. That's correct, but HSQLDB is not supposed to open such a file; it should open the file given in the underlying SET TABLE X SOURCE statement
"/tmp/2012-06-14T20-32-01.594+0200/txn/branches/5.8/zaviation/db/initialdata/t_text.csv"

You guessed it right - my database script resides in "/tmp/2012-06-14T20-32-01.594+0200" having name "meta"; the two paths are concatenated resulting in a wrong file path.

When running my program, I use java -Dtextdb.allow_full_path=true MyClass

Discussion

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-09-13

    I guess I figured out the problem! In method org.hsqldb.persist.Logger.getSecurePath(String) the textdb.allow_full_path property is only evaluated if the path contains "..". I suggest the following bugfix:

    /**
    * Returns a secure path or null for a user-defined path when
    * hsqldb.allow_full_path is false. Returns the path otherwise.
    *
    */
    public String getSecurePath(String path) {

    if (database.getType() == DatabaseURL.S_RES) {
    return path;
    }

    // check the textdb.allow_full_path property first..
    if (database.logger.propTextAllowFullPath) {
    // if textdb.allow_full_path is set,
    // use the given path without prepending the database location
    return FileUtil.getFileUtil().canonicalOrAbsolutePath(path);
    }

    if(path.contains("..")) {
    // if textdb.allow_full_path is not set,
    // forbid access to parent directory
    return null;
    }

    // textdb.allow_full_path property is not set
    // and we don't access the parent directory:
    // compose the path of the database location and the given path
    String fullPath =
    new File(new File(database.getPath()
    + ".properties").getAbsolutePath()).getParent();

    if (fullPath != null) {
    path = fullPath + File.separator + path;
    }

    return path;
    }

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-09-13

    Logger.java with my bugfix

     
  • Fred Toussi

    Fred Toussi - 2012-10-02

    The latest strategy is to treat paths that start with slash, backslash or that contain the colon as absolute paths. All other paths are appended to database directory path.

    Changes committed and featured in the latest snapshot jar.

     
  • Fred Toussi

    Fred Toussi - 2012-10-02
    • labels: --> engine 2.0
    • priority: 5 --> 1
    • assigned_to: nobody --> fredt
    • status: open --> open-fixed
     
  • Fred Toussi

    Fred Toussi - 2013-12-30
    • status: open-fixed --> closed-fixed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks