Repository: python-pillow/Pillow

Issue:
Can't open a tiff with old-style jpeg compressed file
<!--
Thank you for reporting an issue.

Follow these guidelines to ensure your issue is handled properly.

If you have a ...

1.  General question: consider asking the question on Stack Overflow
    with the python-imaging-library tag:

    * https://stackoverflow.com/questions/tagged/python-imaging-library

    Do not ask a question in both places.

    If you think you have found a bug or have an unexplained exception
    then file a bug report here.

2.  Bug report: include a self-contained, copy-pastable example that
    generates the issue if possible. Be concise with code posted.
    Guidelines on how to provide a good bug report:

    * https://stackoverflow.com/help/mcve

    Bug reports which follow these guidelines are easier to diagnose,
    and are often handled much more quickly.

3.  Feature request: do a quick search of existing issues
    to make sure this has not been asked before.

We know asking good questions takes effort, and we appreciate your time.
Thank you.
-->

### What did you do?
I can get the infomation from tiffinfo.
```console
$ tiffinfo 20230822143148.tif 
TIFF Directory at offset 0x8 (8)
  Subfile Type: multi-page document (2 = 0x2)
  Image Width: 2340 Image Length: 1654
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 8
  Compression Scheme: Old-style JPEG
  Photometric Interpretation: min-is-black
  FillOrder: msb-to-lsb
  YCbCr Subsampling: 2, 2
  YCbCr Positioning: centered
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 1654
  Planar Configuration: single image plane
  Page Number: 0-0
  Software: Apeos C7070
  JpegInterchangeFormat: 306
  JpegInterchangeFormatLength: 405550
  JpegProc: 1
  JpegRestartInterval: 0
```

But when i use python, get the under error.
`PIL.UnidentifiedImageError: cannot identify image file '20230822143148.tif'`

### What did you expect to happen?
Pillow will open the file without error.

### What actually happened?
I get the under error.
`PIL.UnidentifiedImageError: cannot identify image file '20230822143148.tif'`

### What are your OS, Python and Pillow versions?

* OS: Windows 10 (22H2)
* Python: 3.9.13
* Pillow: 9.5.0

<!--
Please include **code** that reproduces the issue and whenever possible, an **image** that demonstrates the issue. Please upload images to GitHub, not to third-party file hosting sites. If necessary, add the image to a zip or tar archive.

The best reproductions are self-contained scripts with minimal dependencies. If you are using a framework such as Plone, Django, or Buildout, try to replicate the issue just using Pillow.
-->

```python
code goes here
```



Discussion:
Can you attach a copy of the image itself?
[20230822143148.zip](https://github.com/python-pillow/Pillow/files/12682749/20230822143148.zip)
@radarhere 

I upload it.
Test code.

```python
import sys
from PIL import Image, TiffImagePlugin, features

filename = sys.argv[1]

TiffImagePlugin.DEBUG = True
TiffImagePlugin.READ_LIBTIFF = True

with Image.open(filename, mode='r', formats=['TIFF']) as img:
  img.load()
  TiffImagePlugin.READ_LIBTIFF = False
  print(img.width, img.height)
  print(img.info)

print(features.version_codec("libtiff"))
```

Resolving patch:
diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py
--- a/src/PIL/TiffImagePlugin.py
+++ b/src/PIL/TiffImagePlugin.py
@@ -251,6 +251,8 @@
     (II, 5, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0)): ("CMYK", "CMYKXX"),
     (MM, 5, (1,), 1, (8, 8, 8, 8, 8, 8), (0, 0)): ("CMYK", "CMYKXX"),
     (II, 5, (1,), 1, (16, 16, 16, 16), ()): ("CMYK", "CMYK;16L"),
+    (II, 6, (1,), 1, (8,), ()): ("L", "L"),
+    (MM, 6, (1,), 1, (8,), ()): ("L", "L"),
     # JPEG compressed images handled by LibTiff and auto-converted to RGBX
     # Minimal Baseline TIFF requires YCbCr images to have 3 SamplesPerPixel
     (II, 6, (1,), 1, (8, 8, 8), ()): ("RGB", "RGBX"),


Test patch: