-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows: os.get_raw_line - buffer overflow #23764
Comments
Connected to Huly®: V_0.6-22178 |
V should definitely be giving you an error message, but it is definitely a problem in your code. To make it work, all you have to do is actually fill out the struct Log {
timestamp string @[json: '@timestamp']
version string @[json: '@version']
message string
logger_name string
thread_name string
level string
level_value int
uid string
request_id string
session_log_id string
ip string
referer string
processing_time_ms int
method string
content_type string
query string
type string
request_uri string
status int
} then it works as it is supposed to work:
|
|
If you don't know all the fields ahead of time, then try switching to It has methods for "raw" parsing (without needing a struct), turning the parsed values into a map for easier access, etc. |
I think is not json nor the empty Log struct. I did this in playground (without reading any file). Then paste it in windows and worked. Maybe the problem could be some windows file reading I am still don't check. import json
const lines = [
'{"@timestamp":"2025-02-19T15:45:49.746Z","@version":"1","message":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","logger_name":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","thread_name":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","level":"INFO","level_value":20000,"uid":"","request_id":"xxxxxx","session_log_id":"xxxxxxxxxxx","ip":"xxx.xxx.xxx.xxx","referer":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx012345678901234567890123456","processing_time_ms":0,"method":"GET","content_type":"text/javascript","query":null,"type":"xxxxxxxxxxxxxxxx","request_uri":"/pub/js/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.js","status":200}'
'{"@timestamp":"2025-02-19T15:45:49.746Z","@version":"1","message":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","logger_name":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","thread_name":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","level":"INFO","level_value":20000,"uid":"","request_id":"xxxxxx","session_log_id":"xxxxxxxxxxx","ip":"xxx.xxx.xxx.xxx","referer":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","processing_time_ms":0,"method":"GET","content_type":"text/javascript","query":null,"type":"xxxxxxxxxxxxxxxx","request_uri":"/pub/js/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.js","status":200}'
'{"@timestamp":"2025-02-19T15:45:49.746Z","@version":"1","message":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","logger_name":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","thread_name":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","level":"INFO","level_value":20000,"uid":"","request_id":"xxxxxx","session_log_id":"xxxxxxxxxxx","ip":"xxx.xxx.xxx.xxx","referer":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","processing_time_ms":0,"method":"GET","content_type":"text/javascript","query":null,"type":"xxxxxxxxxxxxxxxx","request_uri":"/pub/js/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.js","status":200}'
]
struct Log {
}
fn main() {
for i, line in lines {
line2 := line.trim_right('\r\n')
json.decode(Log, line2) or {
println('${i}: ${line2}')
continue
}
println("${i}: OK")
}
}
|
I remove module main
import os
import json
struct Log {
}
fn main() {
mut i:= 0
for {
i += 1
mut line := os.get_raw_line()
if line.len == 0 {
break
}
json.decode(Log, line) or {
println('${i}: ${line.len} ${err}')
continue
}
println("${i}: ${line.len} OK")
}
} Then I compile the program to an exe and use
Now I added two returns at the start of the txt file and three lines with data can be read ok:
|
|
The problem is It allocates 256 "chars" / 512 bytes ( https://github.com/vlang/v/blob/master/vlib/os/os.c.v#L506 ) but it doesn't do any reallocation or checks if more memory is needed ( https://github.com/vlang/v/blob/master/vlib/os/os.c.v#L519-L533 )
module main
import os
fn main() {
assert os.get_raw_line().contains("abcdefghijklmnopqrstuvwxyz")
} |
Root cause described here: #23764 (comment)
Describe the bug
On Windows 10 (no issue on WSL) I get a
RUNTIME ERROR: invalid memory access
.LE.
or { }
blockReproduction Steps
Create a file yyy:
main.v:
Run
Expected Behavior
The output of the script should be:
1: OK
2: OK
3: OK
Current Behavior
Possible Solution
No response
Additional Information/Context
In addition, the first line logged in the console misses some
x
characters.V version
0.4.9 99635cf
Environment details (OS name and version, etc.)
Windows 10
The text was updated successfully, but these errors were encountered: