Skip to content

Commit

Permalink
Merge pull request #8 from tractordev/cat-fix
Browse files Browse the repository at this point in the history
Fix `os.ReadFile` OOM
  • Loading branch information
progrium authored Nov 7, 2023
2 parents 3acd882 + d3578bd commit 3435d7f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
14 changes: 7 additions & 7 deletions kernel/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *Service) read(this js.Value, args []js.Value) any {
// buf := make([]byte, length)
// n, err := StdinBuf.Read(buf)
// if err != nil {
// cb.Invoke(jsError(err))
// cb.Invoke(jsError(err), 0)
// return
// }
// js.CopyBytesToJS(jsbuf, buf[:n])
Expand All @@ -196,27 +196,27 @@ func (s *Service) read(this js.Value, args []js.Value) any {
f, ok := s.fds[fd]
s.mu.Unlock()
if !ok {
cb.Invoke(jsError(syscall.EBADF))
cb.Invoke(jsError(syscall.EBADF), 0)
return
}

if rs, ok := f.File.(io.ReadSeeker); ok && !pos.IsNull() {
_, err := rs.Seek(int64(pos.Int()), 0)
if err != nil {
cb.Invoke(jsError(err))
cb.Invoke(jsError(err), 0)
return
}
}

buf := make([]byte, length)
n, err := f.Read(buf)
if err != nil && err != io.EOF {
cb.Invoke(jsError(err))
return
}
if n > 0 {
js.CopyBytesToJS(jsbuf, buf[:n])
}
if err != nil && err != io.EOF {
cb.Invoke(jsError(err), n)
return
}

cb.Invoke(nil, n)
}()
Expand Down
10 changes: 3 additions & 7 deletions kernel/web/lib/syscall.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions kernel/web/lib/wasm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3435d7f

Please sign in to comment.