Relatorio

Bug 44

classification
Title: mimetype should be first in zip file
Type: behavior Severity: normal
Components: opendocument Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ced Nosy List: ced, risto3, roundup-bot
Priority: normal Keywords: patch

Created on 2018-05-05 19:37 by risto3, last changed 2018-05-16 23:49 by ced.

Messages
msg72 Author: [hidden] (risto3) Date: 2018-05-05 19:37
as suggested in https://bugs.tryton.org/issue7409
this bug report indicates that there are cases where invalid
Opendocument files are generated.

version used : relatorio 0.8.0
msg73 Author: [hidden] (ced) Date: 2018-05-05 20:02
The generated files are not invalid. It is just that the
magic of libmagic does not operate.

This is an improvement to overcome the limitation of libmagic.
msg74 Author: [hidden] (ced) Date: 2018-05-05 20:06
Indeed mimetype shall be the first but the mimetype file is
optional "should".
http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os-part3.html#__RefHeading__752809_826425813
msg75 Author: [hidden] (risto3) Date: 2018-05-05 20:17
sorry, but perhaps you should take a moment to reread 3.3

In the first case, a mime type exists for the document type
therefore the file mimetype *should* exist.

Secondly, the file named “META-INF/manifest.xml” contains a
<manifest:file-entry> element whose manifest:full-path
attribute has the value "/".

Therefore a "mimetype" file *shall* exist

Ergo, the content of the “mimetype” file shall be equal to
the value of the manifest:media-type attribute 4.8.10 of
that element.

(Within the normative text of this specification, the terms
“shall”, “shall not”, “should”, “should not”, “may” and
“need not” are to be interpreted as described in Annex H of
[ISO/IEC Directives].)
msg76 Author: [hidden] (risto3) Date: 2018-05-05 23:25
BTW, after unzipping the Trial-Balance.odt into a tmp
directory and then:
zip -0 -X ../Trial-Balance2.odt mimetype
zip -r ../Trial-Balance2.odt * -x mimetype

$ zipinfo Trial-Balance2.odt 
Archive:  Trial-Balance2.odt
Zip file size: 9874 bytes, number of entries: 7
-rw-------  3.0 unx       39 b- stor 18-May-05 16:14 mimetype
-rw-------  3.0 unx    21709 tx defN 18-May-05 16:14 content.xml
drwxr-xr-x  3.0 unx        0 bx stor 18-May-05 23:10 META-INF/
-rw-------  3.0 unx      594 tx defN 18-May-05 16:14
META-INF/manifest.xml
-rw-------  3.0 unx     2547 tx defN 18-May-05 16:14 meta.xml
-rw-------  3.0 unx    12914 tx defN 18-May-05 16:14
settings.xml
-rw-------  3.0 unx    27006 tx defN 18-May-05 16:14 styles.xml
7 files, 64809 bytes uncompressed, 8850 bytes compressed:  86.3%
$ file -i Trial-Balance2.odt
Trial-Balance2.odt: application/vnd.oasis.opendocument.text;
charset=binary
$ xxd Trial-Balance2.odt |head -5
00000000: 504b 0304 0a00 0000 0000 d881 a54c 5ec6 
PK...........L^.
00000010: 320c 2700 0000 2700 0000 0800 0000 6d69 
2.'...'.......mi
00000020: 6d65 7479 7065 6170 706c 6963 6174 696f 
metypeapplicatio
00000030: 6e2f 766e 642e 6f61 7369 732e 6f70 656e 
n/vnd.oasis.open
00000040: 646f 6375 6d65 6e74 2e74 6578 7450 4b03 
document.textPK.

xdg-open works now fine on this document.
msg77 Author: [hidden] (ced) Date: 2018-05-05 23:43
I read it carefully and it say *SHOULD* so it is only
recommended to have this mimetype file.
msg78 Author: [hidden] (ced) Date: 2018-05-06 00:08
Here is review50321002
msg81 Author: [hidden] (risto3) Date: 2018-05-06 06:14
This patch works for me.

Note, the generated file contains META-INF/manifest, which
(pretty printed) consists of:

$ xmlstarlet ed manifest.xml 
<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest
xmlns:manifest="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0">
  <manifest:file-entry manifest:full-path="/"
manifest:media-type="application/vnd.oasis.opendocument.text"/>
  <manifest:file-entry manifest:full-path="meta.xml"
manifest:media-type="text/xml"/>
  <manifest:file-entry manifest:full-path="settings.xml"
manifest:media-type="text/xml"/>
  <manifest:file-entry manifest:full-path="content.xml"
manifest:media-type="text/xml"/>
  <manifest:file-entry manifest:full-path="styles.xml"
manifest:media-type="text/xml"/>
</manifest:manifest>

Notice the full-path="/"

Quoting the third stanza in 3.3 MIME Media Type:
'''
If the file named “META-INF/manifest.xml” contains a
<manifest:file-entry> element whose manifest:full-path
attribute has the value "/", then a "mimetype" file shall
exist, and the content of the “mimetype” file shall be equal
to the value of the manifest:media-type attribute 4.8.10 of
that element.
'''

In this context, 'Shall' (required) now overrides 'should'
(recommended).

For what it's worth:
'''
    "shall" indicates a requirement
    "should" indicates a recommendation
    "may" is used to indicate that something is permitted
    "can" is used to indicate that something is possible,
for example, that an organization or individual is able to
do something

In the ISO/IEC Directives, Part 2, Seventh edition, 2016,
3.3.3, a requirement is defined as an "expression in the
content of a document conveying objectively verifiable
criteria to be fulfilled and from which no deviation is
permitted if compliance with the document is to be claimed."

In the ISO/IEC Directives, Part 2, Seventh edition, 2016,
3.3.4, a recommendation is defined as an "expression in the
content of a document conveying a suggested possible choice
or course of action deemed to be particularly suitable
without necessarily mentioning or excluding others."
'''

This patch is therefore necessary in order to generate a
file conformant to the requirements document.

Thank you in advance for your prompt commit and release of
this important fix.
msg82 Author: [hidden] (roundup-bot) Date: 2018-05-16 23:48
New changeset 925182b4fb9a by Cédric Krier in branch 'default':
Write mimetype as first file of the zip file
https://hg.tryton.org/relatorio/rev/925182b4fb9a
History
Date User Action Args
2018-05-16 23:49:09cedsetresolution: fixed
2018-05-16 23:48:52roundup-botsetstatus: open -> closed
nosy: + roundup-bot
messages: + msg82
2018-05-06 06:14:51risto3setmessages: + msg81
2018-05-06 00:08:43cedsetkeywords: + patch
assignee: ced
messages: + msg78
2018-05-05 23:46:08cedsettitle: generated report filetype default mimetype application/zip and not application/vnd.oasis.opendocument.text -> mimetype should be first in zip file
2018-05-05 23:43:14cedsetmessages: + msg77
2018-05-05 23:25:38risto3setmessages: + msg76
2018-05-05 20:17:33risto3setmessages: + msg75
2018-05-05 20:06:53cedsetmessages: + msg74
severity: minor -> normal
2018-05-05 20:02:43cedsetnosy: + ced
messages: + msg73
2018-05-05 20:00:38cedsetstatus: new -> open
priority: immediate -> normal
severity: critical -> minor
2018-05-05 19:37:17risto3create