Posted 13 June 2015 - 09:30 PM
Derpy edit: forgot to mention, this would fix the http issue :P/>
Reading binary with BufferedReader is bad, since it messes up the input.
The above image shows a diagram about the bytes. I started a localhost server with a file that contains all the bytes in order (00, 01 … 7F, 80, 81 … FE, FF), then downloaded it in CC1.73 via HTTP. Here's the result:
CL (clear line) turned into LF (line feed), and all non-ANSI-printable (HxD shows nothing there) characters (interestingly, all of them are in the ISO-8859-1 charset) are turned into a question mark (3F). This may be caused by the evil Buffered(Reader|Writer) trying to convert those characters into meaningful ones, since it's only meant for text, and not binary.
Proofing this with java (WARNING! spoiler hell)
It produced this output:
Note: The bintest2 file is not important now.
The pattern is familiar, isn't it? (rednet pls)
Now let's try to load a perfect binfile1 (with all the bytes (00, 01, 02 … 7E, 7F, 80, 81, 82 … FE, FF) present)
The binfile2 gives an interesting result:
Note: if you see a perfect binfile1 here, then look harder (for example, it's "80 3F 82 3F 84" instead of "80 81 82 83 84")
This result is the binary equivalent of the downloaded file. (Note: the first image shows the downloaded file after some hackery testing and image editing, but trust me, it's the same (or try it out yourself :P/>))
So long story short: Lua and LuaJ has nothing to do with this bug. It's the Buffered(Reader|Writer) who's the <censored> :P/>
I'll play a bit more with Data(Input|Output)Stream-s and report the progress.
Edit: here's a fix I wrote: http://pastebin.com/z4NajPBU
Note that this fix corrupts binary files at the newline charaters (CL and LF), but why would someone read binary data using readLine()? :P/>
Reading binary with BufferedReader is bad, since it messes up the input.
The above image shows a diagram about the bytes. I started a localhost server with a file that contains all the bytes in order (00, 01 … 7F, 80, 81 … FE, FF), then downloaded it in CC1.73 via HTTP. Here's the result:
CL (clear line) turned into LF (line feed), and all non-ANSI-printable (HxD shows nothing there) characters (interestingly, all of them are in the ISO-8859-1 charset) are turned into a question mark (3F). This may be caused by the evil Buffered(Reader|Writer) trying to convert those characters into meaningful ones, since it's only meant for text, and not binary.
Proofing this with java (WARNING! spoiler hell)
Spoiler
Here's the code I used: http://pastebin.com/Whh2u0JEIt produced this output:
Note: The bintest2 file is not important now.
The pattern is familiar, isn't it? (rednet pls)
Now let's try to load a perfect binfile1 (with all the bytes (00, 01, 02 … 7E, 7F, 80, 81, 82 … FE, FF) present)
Spoiler
Comment out lines #19-24 (leaving "BufferedWriter bw;" there), and change at line#42 toSpoiler
for(int i = 0; i != str.length(); i++)
{
bw.write(String.valueOf(str.charAt(i)));
}
The binfile2 gives an interesting result:
Note: if you see a perfect binfile1 here, then look harder (for example, it's "80 3F 82 3F 84" instead of "80 81 82 83 84")
This result is the binary equivalent of the downloaded file. (Note: the first image shows the downloaded file after some hackery testing and image editing, but trust me, it's the same (or try it out yourself :P/>))
So long story short: Lua and LuaJ has nothing to do with this bug. It's the Buffered(Reader|Writer) who's the <censored> :P/>
Edit: here's a fix I wrote: http://pastebin.com/z4NajPBU
Note that this fix corrupts binary files at the newline charaters (CL and LF), but why would someone read binary data using readLine()? :P/>
Edited on 14 June 2015 - 02:34 PM