### ImageMagick version

7.1.1-12

### Operating system

Linux

### Operating system, version and so on

Arch Linux Rolling - kernel 6.4.1-arch1-1

### Description

The `convert` utility fails to load a valid 180x215 image encoded in 1-bit monochrome using the `gray` coder, resulting in an unexpected end-of-file error on line 245 in `gray.c`. No issue occurs when loading an image encoded the same way of resolution 256x256. The former file has a size of 4838 bytes, which according to the calculation `180x215/8`, it is enough bytes to fit such image. The images are generated by my own dithering utility, however are valid and have worked every other time.

### Steps to Reproduce

1. Download the files `david_4838.gray` and `david_8192.gray`
2. Run the command `convert -size 256x256 -depth 1 david_8192.gray david_8192.png` - expected behavior, file is loaded and converted to PNG.
3. Run the command `convert -size 180x215 -depth 1 david_4838.gray david_4838.png` - receive the following error:
```
convert: unexpected end-of-file 'david_4838.gray': Invalid argument @ error/gray.c/ReadGRAYImage/245.
convert: no images defined `david_4838.png' @ error/convert.c/ConvertImageCommand/3342.
```
4. Use another utility like [rawpixels.net](https://rawpixels.net/), specifying the file format - expected behavior, file is loaded (albeit with slightly incorrect color levels, that's on them).

### Images

`david_4838.gray` and `david_8192.gray`:
[david.tar.gz](https://github.com/ImageMagick/ImageMagick/files/11956331/david.tar.gz)

Converted `david_8192.gray`:
![david_8192](https://github.com/ImageMagick/ImageMagick/assets/39885272/ad430c14-c724-4a18-92b3-37eea797b697)

Converted `david_4838.gray` using rawpixels:
![david_4838](https://github.com/ImageMagick/ImageMagick/assets/39885272/db53cbbe-aeeb-4d38-8f88-010627b545e5)

Original source image:
![david](https://github.com/ImageMagick/ImageMagick/assets/39885272/eb991cdc-5507-43c2-b202-128e00783bdf)

Unexpected end-of-file error when loading valid 180x215 1-bit gray format image
This is a GitHub Issue
repo:ImageMagick
owner:ImageMagick
Title : Unexpected end-of-file error when loading valid 180x215 1-bit gray format image
Issue date:

--- start body ---
### ImageMagick version

7.1.1-12

### Operating system

Linux

### Operating system, version and so on

Arch Linux Rolling - kernel 6.4.1-arch1-1

### Description

The `convert` utility fails to load a valid 180x215 image encoded in 1-bit monochrome using the `gray` coder, resulting in an unexpected end-of-file error on line 245 in `gray.c`. No issue occurs when loading an image encoded the same way of resolution 256x256. The former file has a size of 4838 bytes, which according to the calculation `180x215/8`, it is enough bytes to fit such image. The images are generated by my own dithering utility, however are valid and have worked every other time.

### Steps to Reproduce

1. Download the files `david_4838.gray` and `david_8192.gray`
2. Run the command `convert -size 256x256 -depth 1 david_8192.gray david_8192.png` - expected behavior, file is loaded and converted to PNG.
3. Run the command `convert -size 180x215 -depth 1 david_4838.gray david_4838.png` - receive the following error:
```
convert: unexpected end-of-file 'david_4838.gray': Invalid argument @ error/gray.c/ReadGRAYImage/245.
convert: no images defined `david_4838.png' @ error/convert.c/ConvertImageCommand/3342.
```
4. Use another utility like [rawpixels.net](https://rawpixels.net/), specifying the file format - expected behavior, file is loaded (albeit with slightly incorrect color levels, that's on them).

### Images

`david_4838.gray` and `david_8192.gray`:
[david.tar.gz](https://github.com/ImageMagick/ImageMagick/files/11956331/david.tar.gz)

Converted `david_8192.gray`:
![david_8192](https://github.com/ImageMagick/ImageMagick/assets/39885272/ad430c14-c724-4a18-92b3-37eea797b697)

Converted `david_4838.gray` using rawpixels:
![david_4838](https://github.com/ImageMagick/ImageMagick/assets/39885272/db53cbbe-aeeb-4d38-8f88-010627b545e5)

Original source image:
![david](https://github.com/ImageMagick/ImageMagick/assets/39885272/eb991cdc-5507-43c2-b202-128e00783bdf)

--- end body ---
