yona-lang / yona

Yona is a modern take on a dynamic general-purpose programming language with advanced functional programming, minimalistic ML-like syntax, strict evaluation, for GraalVM polyglot virtual machine (VM).
https://yona-lang.org/
GNU General Public License v3.0
127 stars 6 forks source link

Buffer overflow when saving bigger files #58

Closed ktzee closed 4 years ago

ktzee commented 4 years ago

This works:

do
    small = "https://raw.githubusercontent.com/ktzee/dotfiles/master/.bashrc"
    session = http\Client::session {:follow_redirects = :normal}
    (status, headers, body) = http\Client::get session small {}

    fh = File::open "smallfile" {:write, :create, :binary}
    File::write fh body
    File::close fh
end

This doesn't:

do
    url = "https://github.com/yatta-lang/yatta/releases/latest/download/yatta-component.jar"
    session = http\Client::session {:follow_redirects = :normal}
    (status, headers, body) = http\Client::get session url {}

    fh = File::open "bigfile" {:write, :create, :binary}
    File::write fh body
    File::close fh
end
java.nio.BufferOverflowException at main.hs:
do
    url = "https://github.com/yatta-lang/yatta/releases/latest/download/yatta-component.jar"
    s
java.nio.BufferOverflowException
akovari commented 4 years ago

@ktzee , I fixed the error here. If you don't use :body_encoding = :text in the http\Client::session call, an :ioerror will be raised. You can see it in this testcase: https://github.com/yatta-lang/yatta/blob/d9ff42ec2603ac5341f86a882d795c6067eca142/language/tests/LargeFileDownload.yatta

If you use the latest release, you will see this error being properly thrown.