Solution for a mysterious problem with Brother's brscan4 driver

"simple-scan" was crashing for me when trying to do a "photo" scan on my MFC-L5900DW printer. The stack trace looked like this:

#0  0x00007fffd907b9d2 in make_cache_block () from /usr/lib/x86_64-linux-gnu/sane/
#1  0x00007fffd907a77a in read_scanned_data () from /usr/lib/x86_64-linux-gnu/sane/
#2  0x00007fffd9069d3a in PageScan () from /usr/lib/x86_64-linux-gnu/sane/
#3  0x00007fffd90722b5 in sane_brother4_read () from /usr/lib/x86_64-linux-gnu/sane/
#4  0x000055555557ac04 in ?? ()
#5  0x00007ffff5ff3c55 in ?? () from /lib/x86_64-linux-gnu/
#6  0x00007ffff53e16ba in start_thread (arg=0x7fffd9987700) at pthread_create.c:333
#7  0x00007ffff511741d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

Several bug reports said to simply upgrade brscan4 to a newer version, but that didn't fix anything.

I had two computers with the same version of brscan4 installed, but one could scan without crashing and the other always crashed. This made it possible to do a lot of experiments to try to tease out the source of the problem.

My first observation was that when looking at the TCP stream to the printer with Wireshark, the crashing computer sent "C=RLENGTH" but the working computer sent "C=JPEG J=MID". It looked like the crashing computer was requesting some kind of compression format that the printer didn't support (presumably run-length encoded data) and was choking on the result it got back (presumably JPEG data).

Running "scanimage --help -d 'brother4:net1;dev0'" on the two computers revealed the same options for the scanner, except that the crashing computer provided "--mode '24bit Color'" as an option and the working computer didn't. Both computers had a "24bit Color[Fast]" option, and surprisingly, this option worked on the crashing computer. It seemed that simple-scan was choosing the non-fast option for whatever reason.

Some extensive dives into "" with gdb revealed that the knowledge of supported modes is read from ".ini" files in /opt/brother/scanner/brscan4/models4. My printer's line is:


It seemed that the last number controlled whether the (faulty) "24bit Color" mode was available. So, why was one computer (correctly) disabling this mode and the other not?

/opt/brother/scanner/brscan4/brsanenetdevice4.cfg from the crashing computer:

DEVICE=MFCL5900DW , "MFCL5900DW" , Unknown , NODENAME=BRN3C2AF4738657

/opt/brother/scanner/brscan4/brsanenetdevice4.cfg from the crashing computer:

DEVICE=MFC-L5900DW , "MFC-L5900DW" , 0x4f9:0x3aa , NODENAME=BRN3C2AF4738657

It seemed that I hadn't specified the device model properly when adding the printer with brsaneconfig4 (the dash was missing). Sadly, brsaneconfig4 doesn't immediately catch an invalid model, but silently accepts it and runs with some default settings. Those default settings result in crashes when doing color scans on some printers.

TL;DR: Make sure you use an exact model name from "brsaneconfig4 -q" when adding your scanner. A typo or missing dash will make only some software (simple-scan but not scanimage) crash in only some modes (photo, but not text).

It's possible that people who thought upgrading fixed it really had just reconfigured it correctly when reinstalling.