goncalomb / sane-wasm

A WebAssembly port of the SANE API.

Home Page:https://goncalomb.github.io/sane-wasm/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory Access Violation on SANE's test backend

goncalomb opened this issue · comments

During the sane-wasm build we are suppose to set number_of_devices to 0 (test backend). But I've discovered an issue with that option, see build.sh comment:

sane-wasm/build.sh

Lines 236 to 251 in 3100bc9

# Set test backend's number of devices to 0.
# XXX: Oops what? There is some kind of invalid memory access on the backend
# file deps/backends/backend/test.c, setting number_of_devices to 0 causes
# some weird behavior and it's as if 1 device was selected.
# I've looked briefly into this, but was unable to find the cause,
# it's somehow related to how the option is read with:
# read_option (line, "number_of_devices", ...
# and then used on a for loop:
# for (num = 0; num < init_number_of_devices; num++)
# that loop should never run with init_number_of_devices = 0.
# I've tested this config on my linux distribution version of SANE and
# it triggers a Segmentation Fault so there is definitely a problem there.
# XXX: Setting it to -999 for now, fix this, and revert this to 0.
# The fix should probably be pushed upstream to SANE itself:
# https://gitlab.com/sane-project/backends/-/issues
sed -i "s/^number_of_devices .*/number_of_devices -999/g" "$PREFIX/etc/sane.d/test.conf"

The issue is most likely on the file backends/backend/test.c.

The backends patch should be updated to include the fix: https://github.com/goncalomb/sane-wasm/tree/master/deps. And bonus points for fixing it upstream: https://gitlab.com/sane-project/backends/-/issues.