xydrolase / shap4j

JVM bindings for the SHAP library
MIT License
6 stars 0 forks source link

Fixed a potential data corruption bug in TreeExplainer.fromResource. #6

Closed xydrolase closed 4 years ago

xydrolase commented 4 years ago

Overview

This PR attempts to fix a bug which may lead to incomplete data loading from a resource file. In particular, the old Java code

            byte[] data = new byte[is.available()];
            is.read(data);

does not guarantee that we read every byte from the input stream. If the data file is only partially loaded into the byte array, it will result in data corruption, and consequently either invalid SHAP values, or more severe runtime errors.

The bugfix included in this PR should ensure that we exhaustively read all bytes from a given resource file.