There was a straight up coding error in file_pluginfile(). See MDL-37797. It would be great to add some basic unit tests for the function as there do not seem to be any currently.
Initially at least they don't need to be exhaustive. Just enough to check that the various queries run without error.