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

1.17.1 breaks darktable from opening HEIF files. #1010

Closed
etrigan63 opened this issue Oct 23, 2023 · 18 comments
Closed

1.17.1 breaks darktable from opening HEIF files. #1010

etrigan63 opened this issue Oct 23, 2023 · 18 comments

Comments

@etrigan63
Copy link

Had to downgrade to 1.17.0 to restore functionality.

@bradh
Copy link
Contributor

bradh commented Oct 24, 2023

Could you add a bit more detail on what happens? What is your configuration, what test files are you using, and what messages (if any) are emitted when you run with -d imageio?

@etrigan63
Copy link
Author

etrigan63 commented Oct 24, 2023

The files I am using are produced by my Fuji X-T5 directly. It has HEIF as a storage format. The error presented on the command line is:

1.6447 [rawspeed] (IMG-20231005-0765.hif) virtual std::unique_ptr<rawspeed::RawDecoder> rawspeed::RawParser::getDecoder(const rawspeed::CameraMetaData*), line 91: No decoder found. Sorry.

With -d imageio:

1.6055 [rawspeed] (IMG-20231005-0764.hif) virtual std::unique_ptr<rawspeed::RawDecoder> rawspeed::RawParser::getDecoder(const rawspeed::CameraMetaData*), line 91: No decoder found. Sorry.
     1.6055 [libraw_open] extensions whitelist: `cr3'
     1.6059 Failed to read HEIF file [/home/guru/Pictures/Photos/2023/2023-10-05/IMG-20231005-0764.hif]
     1.6073 [dt_imageio_export_with_flags] mipmap allocation for `unused' failed

Here is a test file:
IMG-20231005-0685.hif.zip

@kmilos
Copy link
Contributor

kmilos commented Oct 24, 2023

1.6447 [rawspeed] (IMG-20231005-0765.hif) virtual std::unique_ptr<rawspeed::RawDecoder> rawspeed::RawParser::getDecoder(const rawspeed::CameraMetaData*), line 91: No decoder found. Sorry.

This is not coming from the actual darktable heif loader, and I believe is unrelated (rawspeed just telling you this is not a raw file).

@kmilos
Copy link
Contributor

kmilos commented Oct 24, 2023

I get this w/ 1.17.1 on Windows/MSYS2:

$ heif-convert.exe IMG-20231005-0685.hif IMG-20231005-0685.png
Could not read HEIF/AVIF file: Invalid input: Invalid box size: Box size (0 bytes) smaller than head
er size (8 bytes)

Could be related to 18d4e55 or feb3cee. @farindk

Mind you, box size of 0 is perfectly valid (means box extends until end of file), as we established in Exiv2/exiv2#2612 with these same "special" Fujifilm HEIFs.

@bradh
Copy link
Contributor

bradh commented Oct 24, 2023

I see the same error as @kmilos, but using heif-info --dump-boxes does show a reasonable layout. Not debugged further yet.

 heif-info --dump-boxes IMG-20231005-0685.hif 
MIME type: image/heic
main brand: heix
compatible brands: mif1, heix
Box: ftyp -----
size: 24   (header size: 8)
major brand: heix
minor version: 0
compatible brands: mif1,heix

Box: meta -----
size: 1007   (header size: 12)
| Box: hdlr -----
| size: 33   (header size: 12)
| pre_defined: 0
| handler_type: pict
| name: 
| 
| Box: 2115a7da-4358-11eb-b378-242ac1302 -----
| size: 40   (header size: 24)
| 
| Box: dinf -----
| size: 36   (header size: 8)
| | Box: dref -----
| | size: 28   (header size: 12)
| | | Box: url  -----
| | | size: 12   (header size: 12)
| | | location: 
| 
| Box: pitm -----
| size: 14   (header size: 12)
| item_ID: 1
| 
| Box: iinf -----
| size: 245   (header size: 12)
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 1
| | item_protection_index: 0
| | item_type: grid
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: false
| | 
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 256
| | item_protection_index: 0
| | item_type: hvc1
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: true
| | 
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 257
| | item_protection_index: 0
| | item_type: hvc1
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: true
| | 
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 258
| | item_protection_index: 0
| | item_type: hvc1
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: true
| | 
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 259
| | item_protection_index: 0
| | item_type: hvc1
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: true
| | 
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 512
| | item_protection_index: 0
| | item_type: jpeg
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: false
| | 
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 513
| | item_protection_index: 0
| | item_type: jpeg
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: false
| | 
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 514
| | item_protection_index: 0
| | item_type: jpeg
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: false
| | 
| | Box: infe -----
| | size: 21   (header size: 12)
| | item_ID: 768
| | item_protection_index: 0
| | item_type: Exif
| | item_name: 
| | content_type: 
| | content_encoding: 
| | item uri type: 
| | hidden item: true
| | 
| | Box: infe -----
| | size: 42   (header size: 12)
| | item_ID: 769
| | item_protection_index: 0
| | item_type: mime
| | item_name: 
| | content_type: application/rdf+xml
| | content_encoding: 
| | item uri type: 
| | hidden item: true
| 
| Box: iref -----
| size: 102   (header size: 12)
| reference with type 'dimg' from ID: 1 to IDs: 256 257 258 259 
| reference with type 'thmb' from ID: 512 to IDs: 1 
| reference with type 'thmb' from ID: 513 to IDs: 1 
| reference with type 'thmb' from ID: 514 to IDs: 1 
| reference with type 'cdsc' from ID: 768 to IDs: 1 
| reference with type 'cdsc' from ID: 769 to IDs: 1 
| 
| Box: iprp -----
| size: 333   (header size: 8)
| | Box: ipco -----
| | size: 267   (header size: 8)
| | | Box: hvcC -----
| | | size: 115   (header size: 8)
| | | configuration_version: 1
| | | general_profile_space: 0
| | | general_tier_flag: 1
| | | general_profile_idc: 4
| | | general_profile_compatibility_flags: 0000.1000 0000.0000 0000.0000 0000.0000 
| | | general_constraint_indicator_flags: 10110000 00000000 00000000 00000000 00000000 00000000 
| | | general_level_idc: 150
| | | min_spatial_segmentation_idc: 0
| | | parallelism_type: 0
| | | chroma_format: 4:2:2
| | | bit_depth_luma: 10
| | | bit_depth_chroma: 10
| | | avg_frame_rate: 0
| | | constant_frame_rate: 1
| | | num_temporal_layers: 1
| | | temporal_id_nested: 1
| | | length_size: 4
| | | <array>
| | | | array_completeness: 0
| | | | NAL_unit_type: 32
| | | | 40 01 0c 01 ff ff 24 08 00 00 03 00 bd 08 00 00 03 00 00 96 18 86 02 40 
| | | <array>
| | | | array_completeness: 0
| | | | NAL_unit_type: 33
| | | | 42 01 01 24 08 00 00 03 00 bd 08 00 00 03 00 00 96 b0 01 ec 20 02 88 4d 94 62 1a ec 84 07 b1 35 05 0d 01 00 80 
| | | <array>
| | | | array_completeness: 0
| | | | NAL_unit_type: 34
| | | | 44 01 c0 10 92 f0 3b 19 
| | | 
| | | Box: ispe -----
| | | size: 20   (header size: 12)
| | | image width: 3936
| | | image height: 2592
| | | 
| | | Box: colr -----
| | | size: 19   (header size: 8)
| | | colour_type: nclx
| | | colour_primaries: 1
| | | transfer_characteristics: 13
| | | matrix_coefficients: 5
| | | full_range_flag: 1
| | | 
| | | Box: pixi -----
| | | size: 16   (header size: 12)
| | | bits_per_channel: 10,10,10
| | | 
| | | Box: ispe -----
| | | size: 20   (header size: 12)
| | | image width: 7728
| | | image height: 5152
| | | 
| | | Box: irot -----
| | | size: 9   (header size: 8)
| | | rotation: 90 degrees (CCW)
| | | 
| | | Box: ispe -----
| | | size: 20   (header size: 12)
| | | image width: 1920
| | | image height: 1280
| | | 
| | | Box: ispe -----
| | | size: 20   (header size: 12)
| | | image width: 640
| | | image height: 480
| | | 
| | | Box: ispe -----
| | | size: 20   (header size: 12)
| | | image width: 160
| | | image height: 120
| | 
| | Box: ipma -----
| | size: 58   (header size: 12)
| | associations for item ID: 1
| | | property index: 4 (essential: false)
| | | property index: 5 (essential: false)
| | | property index: 6 (essential: true)
| | associations for item ID: 256
| | | property index: 1 (essential: true)
| | | property index: 2 (essential: true)
| | | property index: 3 (essential: true)
| | associations for item ID: 257
| | | property index: 1 (essential: true)
| | | property index: 2 (essential: true)
| | | property index: 3 (essential: true)
| | associations for item ID: 258
| | | property index: 1 (essential: true)
| | | property index: 2 (essential: true)
| | | property index: 3 (essential: true)
| | associations for item ID: 259
| | | property index: 1 (essential: true)
| | | property index: 2 (essential: true)
| | | property index: 3 (essential: true)
| | associations for item ID: 512
| | | property index: 7 (essential: false)
| | associations for item ID: 513
| | | property index: 8 (essential: false)
| | associations for item ID: 514
| | | property index: 9 (essential: false)
| 
| Box: idat -----
| size: 16   (header size: 8)
| number of data bytes: 8
| 
| Box: iloc -----
| size: 176   (header size: 12)
| item ID: 1
|   construction method: 1
|   data_reference_index: 0
|   base_offset: 0
|   extents: 0,8 
| item ID: 256
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 642048,1616715 
| item ID: 257
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 2258944,2483467 
| item ID: 258
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 4742656,1892225 
| item ID: 259
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 6635008,2837506 
| item ID: 512
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 20992,568164 
| item ID: 513
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 589312,42519 
| item ID: 514
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 632320,9552 
| item ID: 768
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 4096,4242 
| item ID: 769
|   construction method: 0
|   data_reference_index: 0
|   base_offset: 0
|   extents: 8704,12288 

Box: free -----
size: 3057   (header size: 8)

Box: mdat -----
size: 9468426   (header size: 8)

@kmilos
Copy link
Contributor

kmilos commented Oct 24, 2023

Yes, the layout is fine, and the file is perfectly valid (unless the spec has changed, I'm going by a draft I have access to), just a bit unusual to leave size at 0 for the last box.

Ah, just remembered - it's not just 0 size, it's zero box type as well, since Fujifilm writes some extra null bytes at the end of the file.

IIRC, the spec also says unknown boxes are to be safely ignored, not throw an error...

@etrigan63 I think it's time you let Fujifilm know as well. Although not strictly illegal, their files are a bit unusual and can throw 3rd party SW off, as we've now seen several times.

@bradh
Copy link
Contributor

bradh commented Oct 24, 2023

I agree its valid to have 0 file size to mean "to end of file". I'd have to check on null as a box type.

Adding an extra condition to the sanity check allows heif-info and heif-convert to work ok.

@etrigan63 Nice picture - I guess Dale Chihuly?

@kmilos
Copy link
Contributor

kmilos commented Oct 24, 2023

I'd have to check on null as a box type.

I don't have access to the latest edition, but ISO/IEC 14496-12 (5e, 2015) says

Boxes with an unrecognized type shall be ignored and skipped.

@bradh
Copy link
Contributor

bradh commented Oct 24, 2023

It isn't actually a null box - its an unused part of the mdat. That is valid.

@kmilos
Copy link
Contributor

kmilos commented Oct 24, 2023

It isn't actually a null box - its an unused part of the mdat. That is valid.

Not as far as I remember - I checked mdat size back then and found that the 200 null bytes were actually outside/after the mdat, so they're like an extra box of 0 size and null type...

@farindk
Copy link
Contributor

farindk commented Oct 24, 2023

The problem with that file is that is contains extra zero bytes after the mbox. (@bradh: since the mbox has its size specified, the zero bytes are not part of it).
Consequently, the parser reads those extra byte as a boxes with 0 type and 0 size. While this may be technically correct, it is probably not intended.

@farindk
Copy link
Contributor

farindk commented Oct 24, 2023

I don't know how many bytes they are usually appending. If there are more 0-bytes than the header size, everything is fine, but if there are less 0-bytes than even the header size, the file would be invalid.

@bradh
Copy link
Contributor

bradh commented Oct 24, 2023

Ah, I see. That makes sense.

@kmilos
Copy link
Contributor

kmilos commented Oct 24, 2023

FWIW, I've backported 1918de7 for the MSYS2 package...

@farindk
Copy link
Contributor

farindk commented Oct 24, 2023

Thanks.

@etrigan63
Copy link
Author

I agree its valid to have 0 file size to mean "to end of file". I'd have to check on null as a box type.

Adding an extra condition to the sanity check allows heif-info and heif-convert to work ok.

@etrigan63 Nice picture - I guess Dale Chihuly?

Yep.

@etrigan63
Copy link
Author

Yes, the layout is fine, and the file is perfectly valid (unless the spec has changed, I'm going by a draft I have access to), just a bit unusual to leave size at 0 for the last box.

Ah, just remembered - it's not just 0 size, it's zero box type as well, since Fujifilm writes some extra null bytes at the end of the file.

IIRC, the spec also says unknown boxes are to be safely ignored, not throw an error...

@etrigan63 I think it's time you let Fujifilm know as well. Although not strictly illegal, their files are a bit unusual and can throw 3rd party SW off, as we've now seen several times.

I am not qualified to explain this to the Fujifilm engineers. Is there someone I can refer them to that can explain this to them clearly?

@etrigan63
Copy link
Author

I have pinged my contact over at Fujifilm for guidance on their side. Will keep you informed.

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

4 participants