SimulPiscator / AirSane

Publish SANE scanners to MacOS, Android, and Windows via Apple AirScan.
GNU General Public License v3.0
247 stars 26 forks source link

Segmentation fault on transfer-format option for Epson L3150 #38

Closed merrik closed 2 years ago

merrik commented 3 years ago

I have Epson L3150 scanner and I struggle to make it network shared. I can use scanimage to scan manually but couldn't get AirSane working because of Segmentation fault. Scanner is discoverable and web interface returns valid options. I managed to access scanner with SwingSane, scan starts but images are empty. scanimage works perfectly fine

Looks like sane's backends do not support epsonscan2 at all?

enumerating local devices...
sane_init(nullptr, nullptr)
sane_get_devices() ...
... sane_get_devices() -> SANE_Status Success
sane_exit()
found: epsonscan2:L3150 Series:esci2:usb:ES016E:4419 (EPSON L3150 Series)
sane_init(nullptr, nullptr)
sane_open(epsonscan2:L3150 Series:esci2:usb:ES016E:4419) -> 0x7f806c038ab0
[source] := "Flatbed" -> reload options
sane_close(0x7f806c038ab0)
sane_exit()
stable unique name: epsonscan2:EPSON L3150 Series:1
uuid: d26d9bff-4dce-529a-b7a4-ec731da1002e
published as 'EPSON L3150 Series'
listening on 127.0.0.1:8090
listening on 192.168.88.240:8090
listening on 10.8.0.6:8090
listening on [::1]:8090
listening on [fe80::e23f:49ff:fe77:e9b3]:8090
listening on [fe80::79a8:a404:fba6:e16]:8090
[fe80::cf0:c3f2:f3c4:9ae7] - - [30/Oct/2020:05:28:01 +0300] "GET /eSCL/ScannerCapabilities" 200 2556 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [30/Oct/2020:05:28:01 +0300] "GET /eSCL/ScannerIcon" 200 48698 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [30/Oct/2020:05:28:02 +0300] "GET /eSCL/ScannerStatus" 200 364 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
document format requested: image/jpeg
document format used: image/png
using color gamma of 0.555555
[fe80::cf0:c3f2:f3c4:9ae7] - - [30/Oct/2020:05:28:02 +0300] "POST /eSCL/ScanJobs" 201 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [30/Oct/2020:05:28:02 +0300] "GET /eSCL/ScannerStatus" 200 795 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
sane_init(nullptr, nullptr)
sane_open(epsonscan2:L3150 Series:esci2:usb:ES016E:4419) -> 0x7f8064025a80
[mode] := "Color"
[source] := "Flatbed" -> reload options
[resolution] := 50dpi -> reload options
[tl-x] := 0mm
[tl-y] := 0mm
[br-x] := 216mm
[br-y] := 297mm
sane_start(0x7f8064025a80) with options:
[br-x] = 216mm
[br-y] = 297mm
[brightness] = 0
[contrast] = 0
[dropout] = "None"
[gamma-correction] = 2.2
[image-count] = 0
[long-paper-mode] = 0
[mode] = "Color"
[remove-background] = "None"
[resolution] = 200dpi
[rotate] = "0 degrees"
[scan-area] = "Manual"
[source] = "Flatbed"
[threshold] = 128
[tl-x] = 0mm
[tl-y] = 0mm
[transfer-format] = Segmentation fault

sudo -u saned scanimage -d 'epsonscan2:L3150 Series:esci2:usb:ES016E:4419' -A returns

All options specific to device `epsonscan2:L3150 Series:esci2:usb:ES016E:4419':
  General:
    --mode Color|Grayscale|Monochrome [Color]
        Selects the scan mode (e.g., lineart, monochrome, or color).
    --source Flatbed [Flatbed]
        Selects the scan source (such as a document-feeder).
    --duplex[=(yes|no)] [inactive]
        Selects the ADF mode (yes:duplex/no:simplex)
    --resolution 50..1200dpi (in steps of 1) [200]
        Sets the resolution of the scanned image.
    --x-resolution 50..1200dpi (in steps of 1) [inactive]
        Sets the horizontal resolution of the scanned image.
    --y-resolution 50..1200dpi (in steps of 1) [inactive]
        Sets the vertical resolution of the scanned image.
    --scan-area Letter|A4|A5|A5 (Landscape)|A6|A6 (Landscape)|A8|A8 (Landscape)|B5 [JIS]|Postcard|Postcard (Landscape)|PlasticCard|Maximum|Manual [Manual]
        Select an area to scan based on well-known media sizes.
  Geometry:
    -l 0..215.9mm [0]
        Top-left x position of scan area.
    -t 0..297.18mm [0]
        Top-left y position of scan area.
    -x 0..215.9mm [215.9]
        Width of scan-area.
    -y 0..297.18mm [297.18]
        Height of scan-area.
  Enhancement:
    --deskew[=(yes|no)] [inactive]
        Rotate image so it appears upright.
    --dropout None|Red|Blue|Green [None]
        Selects the dropout.
    --rotate 0 degrees|90 degrees|180 degrees|270 degrees|Auto [0 degrees]
        Rotate
    --skip-blankpages 0..100 (in steps of 1) [inactive]
        Skip Blank Pages Settings.
    --brightness -100..100 (in steps of 1) [0]
        Controls the brightness of the acquired image.
    --contrast -100..100 (in steps of 1) [0]
        Controls the contrast of the acquired image.
    --threshold 0..255 [128]
        Select minimum-brightness to get a white point
  Other:
    --double-feed-detection None [inactive]
        Detection Double Feed
    --gamma-correction 0.5..3 (in steps of 0.0999908) [2.2]
        Selects the gamma correction value from a list of pre-defined devices
        or the user defined table, which can be downloaded to the scanner
    --image-count 1..999 (in steps of 1) [0]
        Image Count
    --long-paper-mode[=(yes|no)] [no]
        Select this mode if you want to scan documents longer than what the
        ADF would normally support. Please note that it only supports automatic
        detection of the document height.
SimulPiscator commented 3 years ago

Thank you for your concise bug report.

I was able to locate the epsonscan2 source code, and will have a look at it. From the description of your device on the Epson site however it seems the device has a wireless option, so you can use it wirelessly from your Mac with Epson's MacOS drivers.

If you omit the debug option when running airsaned, does the segfault still happen?

merrik commented 3 years ago

Thanks for a quick response! Let me know if I can provide you anything useful.

Yes, I turned on debug because airsane crashed when I tried to scan anything over network.

It has wireless option but that's not convenient

SimulPiscator commented 3 years ago

I had a look at the code that initializes the "transfer-format" option in epsonscan2 but could not identify any irregularities. If you comment out the code that writes options to the log, in sanecpp/sanecpp.cpp line 507, do you still get a segfault?

SimulPiscator commented 3 years ago

Looking at the epsonscan2 source code again, I found that the "transfer-format" option is handled as a boolean value when initialized but treated as a string value afterwards. I'm not sure how that would result in a segfault when reading the value from AirSane, but it may well explain your problem. In that case, the fix from my last post would be appropriate (comment out line 507 in sanecpp/sanecpp.cpp, recompile, and install).

merrik commented 3 years ago

Thanks! Commented out line 507 and scanning from webpage works perfectly now

As for mac os standard utility, preview is fine but when I press start scan, it fails, calls exit and finally crashes


[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:08:55 +0300] "GET /eSCL/ScannerStatus" 200 2600 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
document format requested: image/jpeg
document format used: image/png
using color gamma of 0.555555
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:08:55 +0300] "POST /eSCL/ScanJobs" 201 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:08:55 +0300] "GET /eSCL/ScannerStatus" 200 3031 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
sane_init(nullptr, nullptr)
sane_open(epsonscan2:L3150 Series:esci2:usb:ES016E:4419) -> 0x7f909803c030
[mode] := "Color"
[source] := "Flatbed" -> reload options
[resolution] := 600dpi -> reload options
[tl-x] := 0mm
[tl-y] := 1mm
[br-x] := 210mm
[br-y] := 297mm
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:09:56 +0300] "GET /eSCL/ScannerStatus" 200 3043 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:09:56 +0300] "GET /eSCL/ScanJobs/730e2bc0-075b-53e2-acea-3ef91c474a1e/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
...
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:10:38 +0300] "GET /eSCL/ScanJobs/730e2bc0-075b-53e2-acea-3ef91c474a1e/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
sane_cancel(0x7f909803c030)
sane_close(0x7f909803c030)
sane_open(epsonscan2:L3150 Series:esci2:usb:ES016E:4419) -> SANE_Status Error during device I/O
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:10:38 +0300] "GET /eSCL/ScanJobs/730e2bc0-075b-53e2-acea-3ef91c474a1e/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:10:39 +0300] "GET /eSCL/ScanJobs/730e2bc0-075b-53e2-acea-3ef91c474a1e/NextDocument" 404 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:10:39 +0300] "GET /eSCL/ScannerStatus" 200 3052 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:10:39 +0300] "GET /eSCL/ScannerStatus" 200 3052 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:10:39 +0300] "DELETE /eSCL/ScanJobs/730e2bc0-075b-53e2-acea-3ef91c474a1e" 200 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:20:10:39 +0300] "GET /eSCL/ScannerStatus" 200 3052 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
sane_exit()
sane_cancel(0)
Segmentation fault
SimulPiscator commented 3 years ago

It is rather strange that the web interface works but Apple's AirScanScanner does not. It might be that AirScanScanner uses incompatible scan settings, though I would expect an invalid parameter error then, rather than an I/O error.

Anyway, I modified AirSane such that the reported segfault should not occur any more.

merrik commented 3 years ago

Thank you a lot for your help!

I tried different scanning options, airsane crashes when scan called from apple's utility with the following options: colored and 600dpi colored and 1200dpi b&w and 1200 dpi Same options work just fine from web interface

SimulPiscator commented 3 years ago

Maybe there is a difference in bit depth between the web interface, and Apple AirScanScanner?

merrik commented 3 years ago

How can I check that? Looks like airsane crashes after image was successfully scanned and during result retrieving. Can that be related to file size?

SimulPiscator commented 3 years ago

I was referring to the "Number of Colors/Grays" setting in Apple Image Capture.

AirSane does not buffer the entire image, rather it sends scanline per scanline as obtained from SANE. If your scanner finishes scanning before AirSane is doing anything, this will be true to the epsonscan2 backend buffering the image internally.

merrik commented 3 years ago

Interesting, I don't have an options 'Number of colors" in AIC. But I tried scanning with same options but just a small part of an image and it went fine. But when I changed selection to the whole page the result was the same crash


...
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:33 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:34 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:34 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:35 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:35 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:36 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:36 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:37 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
sane_cancel(0x7f7e9c022700)
sane_close(0x7f7e9c022700)
sane_open(epsonscan2:L3150 Series:esci2:usb:ES016E:4419) -> SANE_Status Error during device I/O
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:37 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 503 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:38 +0300] "GET /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b/NextDocument" 404 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:38 +0300] "GET /eSCL/ScannerStatus" 200 2614 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:38 +0300] "GET /eSCL/ScannerStatus" 200 2614 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:38 +0300] "DELETE /eSCL/ScanJobs/e8376a2c-c9b8-51b7-89a4-794b73d91f6b" 200 0 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
[fe80::cf0:c3f2:f3c4:9ae7] - - [31/Oct/2020:23:25:38 +0300] "GET /eSCL/ScannerStatus" 200 2614 "" "AirScanScanner/58CFNetwork/1206Darwin/20.1.0"
SimulPiscator commented 3 years ago

Interesting, I don't have an options 'Number of colors" in AIC.

The option is a drop-down menu at the second position from top.

Judging from implementation of the "transfer-format" option, the epsonscan2 backend is definitely buggy. This may adversely affect your AirSane experience. I have not heard from similar experiences with AirSane, so I have no further suggestions to make, sorry.