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

.h5p files with zipfile records for directories are rejected as invalid #79

Open
ralokt opened this issue Jan 30, 2020 · 0 comments
Open

Comments

@ralokt
Copy link

ralokt commented Jan 30, 2020

Zip files may contain records for directories as well as files. For example, if our tree is

h5p.json
Mylib/
|- semantics.json
|- library.json

the records present in our zip file might be

h5p.json
Mylib/
Mylib/semantics.json
Mylib/library.json

or

h5p.json
Mylib/semantics.json
Mylib/library.json

ie, the Mylib/ entry may or may not be present.

Currently, the HP5Validator class rejects the first case while checking for invalid file extensions. Worse, it provides no specific error message that directory records are not allowed, and instead complains about the directory name having a bogus file extension.

The relevant code was introduced here:

366d8f2#diff-5ca86cd0514d58be6708beff914aba66R829

On UN*X systems, the most straightforward way to create a .h5p file from a directory tree is using the zip utility. For example: $ zip ../mylib.h5p -r . might be used to create the .h5p file from the tree in our previous example. This invokation, however, will create a record for the Mylib/ directory as described above, and the resulting .h5p file will be rejected.

A possible fix might include checking for directories by checking whether the file name ends with a slash. The following additions make the validation succeed for me:

      elseif ($canInstall && strpos($fileName, '/') !== FALSE) {
+        // directory record
+        if (substr($fileName, -1) === '/') {
+          continue;
+        }
        // This is a library file, check that the file type is allowed
        if ($this->h5pC->disableFileCheck !== TRUE && !preg_match($libraryRegExp, $fileName)) {

I'm not submitting a pull request for this yet because I assume there are probably other sanity checks that would make sense here.

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