Menu

#773 Fix: NullReferenceException during scanning on Linux

6.X
open
sane (4)
6.1.2
Bug Fix
Medium
N/A
2020-09-23
2020-07-02
No

I'm trying to get NAPS2 working on Linux (Ubuntu 20.04) with my Epson L6190 AIO printer/scanner. After some trial and error, I've been able to compile NAPS2 on Linux itself with Mono.

I was getting a NullReferenceException, that I have traced down to the use of "lastOption" in the Parse() method in SaneOptionParser.cs, around line 62.

I've discovered that this was caused by NAPS2 failing to parse the first option in the output of:

/bin/scanimage --help --device-name=imagescan:esci:networkscan://192.168.70.10:1865

The offending output line is:

Options specific to device `imagescan:esci:networkscan://192.168.70.10:1865':
  General:
    --source ADF|Document Table [Document Table]
        Document Source
    --resolution 50..1200dpi [75]

Somehow, NAPS2 fails to parse the ---source option. Because of that, ParseOption() does not initialize lastOption. Then during parsing of the description line ("Document Source", the Parse() method tries to set lastOption.Desc which throws a NullReferenceException.

Wrapping that block to protect against an unitialized lastOption helps NAPS2 to complete parsing the output of scanimage.

I wonder as well if lastOption needs to be cleared at the start of each call to ParseOption(), to make sure the Description is stored on the proper option, in case any other option fails to parse.

The bigger question of course is why parsing this --source option fails. I've not been able to track that down yet, but will give it a shot over the weekend.

I'm attaching the full output of the scanimage execution as well for reference.

1 Attachments

Discussion

  • Maarten Boekhold

    The issue is that ParseOption() does not support option values with a space in them. Forward slash also is not supported, eg parsing the following option values is failing:

        --source ADF|Document Table [Document Table]
        --scan-area Executive/Portrait|ISO/A4/Portrait|ISO/A5/Portrait|ISO/A5/Landscape|ISO/A6/Portrait|ISO/A6/Landscape|JIS/B5/Portrait|JIS/B6/Portrait|JIS/B6/Landscape|Letter/Portrait|Manual|Maximum [Manual]
        --rotate 0 degrees|90 degrees|180 degrees|270 degrees|Auto [0 degrees]
    

    (btw degrees as a Unit is not supported either).

    I also see "Auto" (capital A) in here, which I think will fail (in the code, it's written all lower case), as well as Manual and Maximum.

    Putting that 'guard' around the access of 'lastOption' in Parse() allows NAPS2 to continue, but it won't be aware of these scanner options.

     

    Last edit: Maarten Boekhold 2020-07-02
  • Maarten Boekhold

    I have just submitted a Pull Request (#21) that fixes these option parsing errors. At the same time the PR includes 3 tiny changes that allowed me to build and debug NAPS2 using MonoDevelop on Linux.

    Appreciate if this PR can be merged.

     

Log in to post a comment.