# YAML.dump/YAML.load bug

**URL:** <https://rubytalk.org/t/yaml-dump-yaml-load-bug/19935>\
**Category:** ruby-talk\
**Created:** [3 August 2005 20:28 UTC](https://rubytalk.org/t/yaml-dump-yaml-load-bug/19935 "2005-08-03T20:28:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Battley](https://avatars.discourse-cdn.com/v4/letter/p/f07891/32.png) [@Paul\_Battley](https://rubytalk.org/u/Paul_Battley)\
**Post date:** [3 August 2005 20:28 UTC](https://rubytalk.org/t/yaml-dump-yaml-load-bug/19935/1 "2005-08-03T20:28:45Z")

</div>

I have identified what seems to be a bug in the current Ruby  
implementation of YAML.

YAML.dump handles binary data without a problem; it is dumped as  
expected. However, when YAML.load is used to read the same data back  
in, it \*sometimes\* fails. I analysed the exact failure behaviour by  
serialising and deserialising random data, then comparing all the  
failed data until I had pinpointed the exact causes.

These are the criteria for failure:

\* A string is used as a hash key.  
\* The string contains a byte 0x00.  
\* The string contains a byte 0x0a in a non-final position.

When all three criteria are met, YAML.load cannot successfully read  
YAML.dump's output.

I've made a set of test cases to demonstrate the problem:  
[http://po-ru.com/files/breakyaml.rb](http://po-ru.com/files/breakyaml.rb)

In my tests, it fails on 1.8.2 and the current stable snapshot, on  
both Linux/686 and OS X/PPC.

Paul Battley.
