Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Menu
Open sidebar
libtiff
libtiff
Commits
87f580f3
Commit
87f580f3
authored
Dec 06, 2021
by
Even Rouault
Browse files
Merge branch 'fix_319' into 'master'
TIFFReadDirectory: fix OJPEG hack (fixes
#319
) Closes
#319
See merge request
!277
parents
8244c2d5
87881e09
Pipeline
#423501919
passed with stages
in 10 minutes and 23 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
libtiff/tif_dirread.c
View file @
87f580f3
...
...
@@ -3794,50 +3794,7 @@ TIFFReadDirectory(TIFF* tif)
MissingRequired
(
tif
,
"ImageLength"
);
goto
bad
;
}
/*
* Setup appropriate structures (by strip or by tile)
*/
if
(
!
TIFFFieldSet
(
tif
,
FIELD_TILEDIMENSIONS
))
{
tif
->
tif_dir
.
td_nstrips
=
TIFFNumberOfStrips
(
tif
);
tif
->
tif_dir
.
td_tilewidth
=
tif
->
tif_dir
.
td_imagewidth
;
tif
->
tif_dir
.
td_tilelength
=
tif
->
tif_dir
.
td_rowsperstrip
;
tif
->
tif_dir
.
td_tiledepth
=
tif
->
tif_dir
.
td_imagedepth
;
tif
->
tif_flags
&=
~
TIFF_ISTILED
;
}
else
{
tif
->
tif_dir
.
td_nstrips
=
TIFFNumberOfTiles
(
tif
);
tif
->
tif_flags
|=
TIFF_ISTILED
;
}
if
(
!
tif
->
tif_dir
.
td_nstrips
)
{
TIFFErrorExt
(
tif
->
tif_clientdata
,
module
,
"Cannot handle zero number of %s"
,
isTiled
(
tif
)
?
"tiles"
:
"strips"
);
goto
bad
;
}
tif
->
tif_dir
.
td_stripsperimage
=
tif
->
tif_dir
.
td_nstrips
;
if
(
tif
->
tif_dir
.
td_planarconfig
==
PLANARCONFIG_SEPARATE
)
tif
->
tif_dir
.
td_stripsperimage
/=
tif
->
tif_dir
.
td_samplesperpixel
;
if
(
!
TIFFFieldSet
(
tif
,
FIELD_STRIPOFFSETS
))
{
#ifdef OJPEG_SUPPORT
if
((
tif
->
tif_dir
.
td_compression
==
COMPRESSION_OJPEG
)
&&
(
isTiled
(
tif
)
==
0
)
&&
(
tif
->
tif_dir
.
td_nstrips
==
1
))
{
/*
* XXX: OJPEG hack.
* If a) compression is OJPEG, b) it's not a tiled TIFF,
* and c) the number of strips is 1,
* then we tolerate the absence of stripoffsets tag,
* because, presumably, all required data is in the
* JpegInterchangeFormat stream.
*/
TIFFSetFieldBit
(
tif
,
FIELD_STRIPOFFSETS
);
}
else
#endif
{
MissingRequired
(
tif
,
isTiled
(
tif
)
?
"TileOffsets"
:
"StripOffsets"
);
goto
bad
;
}
}
/*
* Second pass: extract other information.
*/
...
...
@@ -4042,41 +3999,6 @@ TIFFReadDirectory(TIFF* tif)
}
/* -- if (!dp->tdir_ignore) */
}
/* -- for-loop -- */
if
(
tif
->
tif_mode
==
O_RDWR
&&
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_tag
!=
0
&&
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_count
==
0
&&
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_type
==
0
&&
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_offset
.
toff_long8
==
0
&&
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_tag
!=
0
&&
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_count
==
0
&&
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_type
==
0
&&
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_offset
.
toff_long8
==
0
)
{
/* Directory typically created with TIFFDeferStrileArrayWriting() */
TIFFSetupStrips
(
tif
);
}
else
if
(
!
(
tif
->
tif_flags
&
TIFF_DEFERSTRILELOAD
)
)
{
if
(
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_tag
!=
0
)
{
if
(
!
TIFFFetchStripThing
(
tif
,
&
(
tif
->
tif_dir
.
td_stripoffset_entry
),
tif
->
tif_dir
.
td_nstrips
,
&
tif
->
tif_dir
.
td_stripoffset_p
))
{
goto
bad
;
}
}
if
(
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_tag
!=
0
)
{
if
(
!
TIFFFetchStripThing
(
tif
,
&
(
tif
->
tif_dir
.
td_stripbytecount_entry
),
tif
->
tif_dir
.
td_nstrips
,
&
tif
->
tif_dir
.
td_stripbytecount_p
))
{
goto
bad
;
}
}
}
/*
* OJPEG hack:
* - If a) compression is OJPEG, and b) photometric tag is missing,
...
...
@@ -4147,6 +4069,88 @@ TIFFReadDirectory(TIFF* tif)
}
}
/*
* Setup appropriate structures (by strip or by tile)
* We do that only after the above OJPEG hack which alters SamplesPerPixel
* and thus influences the number of strips in the separate planarconfig.
*/
if
(
!
TIFFFieldSet
(
tif
,
FIELD_TILEDIMENSIONS
))
{
tif
->
tif_dir
.
td_nstrips
=
TIFFNumberOfStrips
(
tif
);
tif
->
tif_dir
.
td_tilewidth
=
tif
->
tif_dir
.
td_imagewidth
;
tif
->
tif_dir
.
td_tilelength
=
tif
->
tif_dir
.
td_rowsperstrip
;
tif
->
tif_dir
.
td_tiledepth
=
tif
->
tif_dir
.
td_imagedepth
;
tif
->
tif_flags
&=
~
TIFF_ISTILED
;
}
else
{
tif
->
tif_dir
.
td_nstrips
=
TIFFNumberOfTiles
(
tif
);
tif
->
tif_flags
|=
TIFF_ISTILED
;
}
if
(
!
tif
->
tif_dir
.
td_nstrips
)
{
TIFFErrorExt
(
tif
->
tif_clientdata
,
module
,
"Cannot handle zero number of %s"
,
isTiled
(
tif
)
?
"tiles"
:
"strips"
);
goto
bad
;
}
tif
->
tif_dir
.
td_stripsperimage
=
tif
->
tif_dir
.
td_nstrips
;
if
(
tif
->
tif_dir
.
td_planarconfig
==
PLANARCONFIG_SEPARATE
)
tif
->
tif_dir
.
td_stripsperimage
/=
tif
->
tif_dir
.
td_samplesperpixel
;
if
(
!
TIFFFieldSet
(
tif
,
FIELD_STRIPOFFSETS
))
{
#ifdef OJPEG_SUPPORT
if
((
tif
->
tif_dir
.
td_compression
==
COMPRESSION_OJPEG
)
&&
(
isTiled
(
tif
)
==
0
)
&&
(
tif
->
tif_dir
.
td_nstrips
==
1
))
{
/*
* XXX: OJPEG hack.
* If a) compression is OJPEG, b) it's not a tiled TIFF,
* and c) the number of strips is 1,
* then we tolerate the absence of stripoffsets tag,
* because, presumably, all required data is in the
* JpegInterchangeFormat stream.
*/
TIFFSetFieldBit
(
tif
,
FIELD_STRIPOFFSETS
);
}
else
#endif
{
MissingRequired
(
tif
,
isTiled
(
tif
)
?
"TileOffsets"
:
"StripOffsets"
);
goto
bad
;
}
}
if
(
tif
->
tif_mode
==
O_RDWR
&&
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_tag
!=
0
&&
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_count
==
0
&&
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_type
==
0
&&
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_offset
.
toff_long8
==
0
&&
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_tag
!=
0
&&
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_count
==
0
&&
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_type
==
0
&&
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_offset
.
toff_long8
==
0
)
{
/* Directory typically created with TIFFDeferStrileArrayWriting() */
TIFFSetupStrips
(
tif
);
}
else
if
(
!
(
tif
->
tif_flags
&
TIFF_DEFERSTRILELOAD
)
)
{
if
(
tif
->
tif_dir
.
td_stripoffset_entry
.
tdir_tag
!=
0
)
{
if
(
!
TIFFFetchStripThing
(
tif
,
&
(
tif
->
tif_dir
.
td_stripoffset_entry
),
tif
->
tif_dir
.
td_nstrips
,
&
tif
->
tif_dir
.
td_stripoffset_p
))
{
goto
bad
;
}
}
if
(
tif
->
tif_dir
.
td_stripbytecount_entry
.
tdir_tag
!=
0
)
{
if
(
!
TIFFFetchStripThing
(
tif
,
&
(
tif
->
tif_dir
.
td_stripbytecount_entry
),
tif
->
tif_dir
.
td_nstrips
,
&
tif
->
tif_dir
.
td_stripbytecount_p
))
{
goto
bad
;
}
}
}
/*
* Make sure all non-color channels are extrasamples.
* If it's not the case, define them as such.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment