MCJack123 / craftos2

A fast, modern, and feature-filled ComputerCraft emulator written in C++.

Home Page:https://www.craftos-pc.cc

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Seekable file handles allow seeking to `-1`

MasonGulu opened this issue · comments

Describe the bug
When using seek on a seekable file handle you can seek to -1. After this happens any further calls to seek don't change your position in the file, keeping the file handle at -1. Any attempt to write/read the file afterwards results in an error along the lines of "cannot write file"

To Reproduce
Steps to reproduce the behavior:

  1. Open lua
  2. Create a wb or rb file handle
  3. Call seek(nil, -1)
  4. Profits?

Expected behavior
CC on 1.19.3 returns nil and an error string "Position is negative" when attempting to seek below 0.
image

Screenshots
image

Environment (please complete the following information):

  • OS: Kubuntu
  • OS Version: 22.04
  • CraftOS-PC Version: v2.7.2
  • Compiled from source? No

Additional context
Add any other context about the problem here.

image
You can also seek past the end of a file open in rb mode. I'm not sure if this is intended, but it then randomly set the position to -1 and triggered the above bug.