Solves overreading/writing the given arrays and will error out if the
streams asks to do that.
Also does more error checking that the stream is valid and won't
overrun any allocated arrays. Also mitigate integer overflow errors
calculating allocation sizes.
https://bugzilla.gnome.org/show_bug.cgi?id=774859
Original commit message from CVS:
Remove all config.h includes from header files, add it to each source file and remove duplicate config.h includes from several source files