Bug 119686 - Indexed TIFF import problems at image border
Summary: Indexed TIFF import problems at image border
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Julien Nabet
URL:
Whiteboard: target:7.4.0 target:7.3.4
Keywords:
Depends on:
Blocks: Images-TIFF
  Show dependency treegraph
 
Reported: 2018-09-04 08:53 UTC by mahfiaz
Modified: 2022-05-18 15:30 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
0px border.tif Example TIF file, shows bug. (35.30 KB, image/tiff)
2018-09-04 08:54 UTC, mahfiaz
Details
Example document in Draw (16.21 KB, application/vnd.oasis.opendocument.graphics)
2018-09-04 08:56 UTC, mahfiaz
Details
Screenshot of example document (138.52 KB, image/png)
2018-09-04 08:56 UTC, mahfiaz
Details
complex.tif More complex example file. (35.35 KB, image/tiff)
2018-09-04 08:57 UTC, mahfiaz
Details
Screenshot of more complex example. (176.41 KB, image/png)
2018-09-04 08:57 UTC, mahfiaz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mahfiaz 2018-09-04 08:53:44 UTC
Description:
When importing TIFF format image with indexed colors, up to 5 pixels at right edge are dropped and the previous pixel column is repeated instead.

Steps to Reproduce:
1. Download attached image 1px border.tif or complex.tif
2. Drag them to Draw, Writer or Impress.

Actual Results:
Mungled up right side of images. See attached screenshots.

Expected Results:
Pixel perfect image.


Reproducible: Always


User Profile Reset: No



Additional Info:
This bug is pretty old, at least from version 3.5, just got fed up enough today to report it.
Comment 1 mahfiaz 2018-09-04 08:54:38 UTC
Created attachment 144656 [details]
0px border.tif Example TIF file, shows bug.
Comment 2 mahfiaz 2018-09-04 08:56:29 UTC
Created attachment 144657 [details]
Example document in Draw
Comment 3 mahfiaz 2018-09-04 08:56:50 UTC
Created attachment 144658 [details]
Screenshot of example document
Comment 4 mahfiaz 2018-09-04 08:57:28 UTC
Created attachment 144659 [details]
complex.tif More complex example file.
Comment 5 mahfiaz 2018-09-04 08:57:52 UTC
Created attachment 144660 [details]
Screenshot of more complex example.
Comment 6 Buovjaga 2018-09-24 17:50:27 UTC
The artefacts look like bug 56178, do you think it is the same underlying issue?
Comment 7 mahfiaz 2018-09-24 21:12:52 UTC
Thanks for your reply.

I don't think these bugs are much related. That one is about slightly less common compression format in TIFF being incorrectly decompressed (or initially just crashing).
This one is most likely something much simpler, such as simply counting rows and columns incorrectly when decompressing the image.
Comment 8 Buovjaga 2018-09-25 09:38:19 UTC
Ok, I confirmed it in 3.3.0.
Comment 9 QA Administrators 2021-06-28 03:48:07 UTC Comment hidden (obsolete)
Comment 10 Julien Nabet 2022-04-30 19:23:30 UTC
On pc Debian x86-64 with master sources updated today, I could reproduce this.
Here's tiffinfo result on the file:
TIFF Directory at offset 0x8 (8)
  Subfile Type: (0 = 0x0)
  Image Width: 30 Image Length: 165
  Resolution: 600, 600 pixels/inch
  Bits/Sample: 1
  Sample Format: unsigned integer
  Compression Scheme: LZW
  Photometric Interpretation: min-is-white
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 128
  Planar Configuration: single image plane
  SubIFD Offsets:   354
  DocumentName: H:\Desktop\LibO bug\0px border.tif
  Software: GIMP 2.10.6
  DateTime: 2018:09:04 11:06:43
Comment 11 Julien Nabet 2022-05-08 17:54:31 UTC
Code pointer:
https://opengrok.libreoffice.org/xref/core/vcl/source/filter/itiff/itiff.cxx?r=520d8c9e#679

(nCompression = 5 corresponds to LZW, the case here).

+ files vcl/source/filter/itiff/lzwdecom.hxx/cxx

When looking at initial doc then complex doc, it seems that for about the first bit of last byte, if this one is white, the rest of the line is white, if it's black, the rest is black.

Now, I spent several hours on these files and don't know where is the bug.
Also, I find LZW not simple + you must consider tiff use with CLEAR code (256) and EOI code (257).
I wish I had a far better brain...
Comment 12 Julien Nabet 2022-05-12 11:53:42 UTC
Patch waiting for review here:
https://gerrit.libreoffice.org/c/core/+/134235

I was so convinced it was due to lzw decoding but in fact, the pb was more general and present in ConvertScanline.
Image width is 30 pixels, since the parameter of the file was 1bit per pixels, it needs 4 bytes per row (the last 2 bits of byte 4 is unused).
The mechanism to read a full byte was ok, the pb was when reading an incomplete byte (so the fourth one in our case).
Indeed, it's using shifting operation to read each bit of the last byte but the shifting value was the same at each loop.
It explains the previous comment, LO was fetching the same bit for all the remaining bits to read in the fourth byte.

With the patch the initial example and the more complex one works.

Also, it may help for tiff files using 1 bit per pixel with no byte swap/fillorder (I think the most general case), not only those using LZW compression.
Comment 13 mahfiaz 2022-05-12 15:39:07 UTC
Hey, this is some detective level work. Thanks for fixing this!
Comment 14 Commit Notification 2022-05-12 17:31:23 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/891ff1334eb4288668ebf70636d7972af691fa88

tdf#119686: fix tiff with 1 bit per pixel

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 15 Julien Nabet 2022-05-15 10:15:00 UTC
Patch waiting for review for 7.3 branch.
https://gerrit.libreoffice.org/c/core/+/134248
(hope someone will review it, if not, it'll be fixed only from future 7.4.0)
Comment 16 Commit Notification 2022-05-16 08:40:16 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/cc6e2d409328f8e4d06305dde47cdc794945b4d8

tdf#119686: fix tiff with 1 bit per pixel

It will be available in 7.3.4.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 mahfiaz 2022-05-18 15:21:53 UTC
This works like a charm in the daily build. Well done!
Comment 18 Julien Nabet 2022-05-18 15:30:21 UTC
Thank you! Let's put this one to VERIFIED then.