From: t_leitner@... Date: 2018-12-28T08:32:37+00:00 Subject: [ruby-core:90772] [Ruby trunk Bug#15460] Behaviour of String#setbyte changed Issue #15460 has been updated by gettalong (Thomas Leitner). Eregon (Benoit Daloze) wrote: > Why are values higher in HexaPDF? Does it mean multiple bytes need to be written or is it enough to throw away the high bits? > I suspect the latter is rarely correct. This actually happens in the predictor filter of HexaPDF (see https://github.com/gettalong/hexapdf/blob/master/lib/hexapdf/filter/predictor.rb#L166) which is an implementation of the PNG filter types (see https://www.w3.org/TR/2003/REC-PNG-20031110/#9Filter-types). The PNG spec says that all operations are to be taken as unsigned arithmetic modulo 256 and since this is what `String#setbyte` originally did, I just left out the additional module operation. It is not a huge problem for me and I will release a new HexaPDF version with the fix soon. As for whether the modulo operation should be done by `String#setbyte`: Many methods automatically convert arguments to an expected type if possible, e.g. with `#to_str`. Converting an integer to a byte using modulo 256 seems like the most straight-forward way to do this for `String#setbyte`. ---------------------------------------- Bug #15460: Behaviour of String#setbyte changed https://bugs.ruby-lang.org/issues/15460#change-75945 * Author: gettalong (Thomas Leitner) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux] * Backport: 2.4: DONTNEED, 2.5: DONTNEED, 2.6: REQUIRED ---------------------------------------- I just installed Ruby 2.6.0 for benchmarking reasons and found that the change [string.c: setbyte silently ignores upper bits](https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/65804) broke my library/application HexaPDF. Before using String#setbyte I tested how it would respond to values lower than 0 or greater than 255 and found that it automatically performed the needed modulo 256 operation (at least up to Ruby 2.5.3). Therefore I left out the explicit modulo operation for performance reasons. Would it make sense to change the String#setbyte implementation to perform the modulo operation? This would restore compatibility with prior Ruby versions and may be what people would expect. -- https://bugs.ruby-lang.org/ Unsubscribe: