GithubHelp home page GithubHelp logo

macos-fuse-t / go-smb2 Goto Github PK

View Code? Open in Web Editor NEW
71.0 6.0 5.0 236 KB

Lightweight SMB2/3 Server implemented in go

License: GNU Affero General Public License v3.0

Go 100.00%
samba samba-server smb smb2 smb3

go-smb2's People

Contributors

macos-fuse-t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

go-smb2's Issues

Byte array overflow during `Read` operation

I've encountered a consistent issue with the Read operation, specifically when attempting to download large files (10MB+) from an SMB Share to a local folder on my computer using Mac Finder. The operation crashes every time for files that necessitate multiple Read calls, indicating a problem with handling concurrent counting during Read packet / request processing.

Steps to Reproduce

  1. Attempt to read/move a larger file (I test it with 10MB+ files) from an SMB Share (for example to local folder using Finder).
  2. Observe that the operation fails and causes a crash every time.

Context

  • This issue was first noticed yesterday. It's unclear whether it has always been present or if it's a new issue.
  • The library had been working correctly in the past. To eliminate the possibility of recent changes on my end introducing this bug, I cloned the repository again and found that the issue persists, suggesting it is not related to any modifications I might have made.
  • Considering a potential link to a Go version update, I tested with three different versions of Go after noticing a software update via Brew a few days ago. However, the issue occurs across all tested Go versions, which may indicate that the problem is not directly related to the Go version.

It's worth mentioning that write operations and other file manipulations work without any issues. The problem is specifically tied to reading larger files, where multiple Read calls are required.

My setup

  • MacBook Air M2
  • MacOS Sonoma 14.3.1, also tried before upgrade
  • GO version 1.22.0 darwin/arm64 installed via Brew (tried also 1.21.6 and 1.21.5)

This is place where overflow happened every time, its clear that it must be some form of parallel change value of d.p because lines before that exactly handles possible case of overflow very transparently. Also I was able to catch crash via debugger when I checked memory exactly before d.ci[d.p] ^= c and d.p was In range of d.ci.

d.ci[d.p] ^= c

Possible fix

I tried to resolve this by removing async execution via removal of go func() and then it starts working,
but iam not sure about some consequences of my solution.

go-smb2/server/file_tree.go

Lines 609 to 618 in 1e1b5ce

go func() {
t.ioReadSem <- struct{}{}
defer func() { <-t.ioReadSem }()
rsp := new(ErrorResponse)
PrepareAsyncResponse(rsp.Header(), pkt, asyncId, uint32(STATUS_PENDING))
c.sendPacket(rsp, &t.treeConn, ctx)
t.readImpl(ctx, pkt, fileId, open, asyncId)
}()

Screenshot of debugger where is exactly spot of overflow.
image

Folder renaming is not supported

hi

macos finder:
Folder renaming is not supported,
File renameing is support.

Termail:
command line, mv can renameing folder

macos 14.2.1

Dies when scanned by nmap

server output:

INFO[0000] debug level false
INFO[0000] Starting server at 127.0.0.1:8082
ERRO[0034] error: connection error: read tcp 127.0.0.1:8082->127.0.0.1:62926: read: connection reset by peer
ERRO[0044] error: connection error: read tcp 127.0.0.1:8082->127.0.0.1:62951: read: connection reset by peer
ERRO[0050] error: connection error: invalid transport format
ERRO[0055] error: connection error: invalid transport format
ERRO[0060] error: connection error: invalid transport format
ERRO[0065] error: connection error: invalid transport format
ERRO[0070] error: connection error: invalid transport format
ERRO[0075] error: connection error: invalid transport format
ERRO[0085] error: connection error: unexpected EOF
ERRO[0090] error: connection error: unexpected EOF
ERRO[0090] error: connection error: invalid transport format
ERRO[0098] error: connection error: invalid transport format
ERRO[0103] error: connection error: invalid transport format
ERRO[0108] error: connection error: invalid transport format
panic: runtime error: slice bounds out of range [:50831452] with capacity 113

goroutine 114 [running]:
github.com/macos-fuse-t/go-smb2/server.(*conn).runReciever(0x1400018a800)
	/Users/name/code/go-smb2/server/conn.go:266 +0x94c
created by github.com/macos-fuse-t/go-smb2/server.(*Server).Serve in goroutine 19
	/Users/name/code/go-smb2/server/server.go:203 +0x4ec

nmap output:

Starting Nmap 7.94 ( https://nmap.org ) at 2023-11-30 09:00 PST
Stats: 0:00:36 elapsed; 0 hosts completed (1 up), 1 undergoing Service Scan
Service scan Timing: About 0.00% done
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00010s latency).
Other addresses for localhost (not scanned): ::1

PORT     STATE SERVICE          VERSION
8082/tcp open  blackice-alerts?

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 68.94 seconds

nmap arguments: nmap -p 8082 localhost -A

thanks,
kelsey

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.