Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
aad68011
Unverified
Commit
aad68011
authored
Dec 08, 2020
by
Nemanja Zbiljić
Committed by
GitHub
Dec 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean file path from tar archive (#1027)
parent
268c615e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
2 deletions
+46
-2
dirs.go
pkg/api/dirs.go
+12
-1
dirs_test.go
pkg/api/dirs_test.go
+34
-1
No files found.
pkg/api/dirs.go
View file @
aad68011
...
...
@@ -15,6 +15,7 @@ import (
"mime"
"net/http"
"path/filepath"
"runtime"
"strings"
"github.com/ethersphere/bee/pkg/collection/entry"
...
...
@@ -129,7 +130,17 @@ func storeDir(ctx context.Context, reader io.ReadCloser, log logging.Logger, p p
return
swarm
.
ZeroAddress
,
fmt
.
Errorf
(
"read tar stream: %w"
,
err
)
}
filePath
:=
fileHeader
.
Name
filePath
:=
filepath
.
Clean
(
fileHeader
.
Name
)
if
filePath
==
"."
{
logger
.
Warning
(
"skipping file upload empty path"
)
continue
}
if
runtime
.
GOOS
==
"windows"
{
// always use Unix path separator
filePath
=
filepath
.
ToSlash
(
filePath
)
}
// only store regular files
if
!
fileHeader
.
FileInfo
()
.
Mode
()
.
IsRegular
()
{
...
...
pkg/api/dirs_test.go
View file @
aad68011
...
...
@@ -226,6 +226,33 @@ func TestDirs(t *testing.T) {
},
},
},
{
name
:
"invalid archive paths"
,
files
:
[]
f
{
{
data
:
[]
byte
(
"<h1>Swarm"
),
name
:
"index.html"
,
dir
:
""
,
filePath
:
"./index.html"
,
reference
:
swarm
.
MustParseHexAddress
(
"bcb1bfe15c36f1a529a241f4d0c593e5648aa6d40859790894c6facb41a6ef28"
),
},
{
data
:
[]
byte
(
"body {}"
),
name
:
"app.css"
,
dir
:
""
,
filePath
:
"./app.css"
,
reference
:
swarm
.
MustParseHexAddress
(
"9813953280d7e02cde1efea92fe4a8fc0fdfded61e185620b43128c9b74a3e9c"
),
},
{
data
:
[]
byte
(
`User-agent: *
Disallow: /`
),
name
:
"robots.txt"
,
dir
:
""
,
filePath
:
"./robots.txt"
,
reference
:
swarm
.
MustParseHexAddress
(
"84a620dcaf6b3ad25251c4b4d7097fa47266908a4664408057e07eb823a6a79e"
),
},
},
},
}
{
t
.
Run
(
tc
.
name
,
func
(
t
*
testing
.
T
)
{
// tar all the test case files
...
...
@@ -396,9 +423,14 @@ func tarFiles(t *testing.T, files []f) *bytes.Buffer {
tw
:=
tar
.
NewWriter
(
&
buf
)
for
_
,
file
:=
range
files
{
filePath
:=
path
.
Join
(
file
.
dir
,
file
.
name
)
if
file
.
filePath
!=
""
{
filePath
=
file
.
filePath
}
// create tar header and write it
hdr
:=
&
tar
.
Header
{
Name
:
path
.
Join
(
file
.
dir
,
file
.
name
)
,
Name
:
filePath
,
Mode
:
0600
,
Size
:
int64
(
len
(
file
.
data
)),
}
...
...
@@ -425,6 +457,7 @@ type f struct {
data
[]
byte
name
string
dir
string
filePath
string
reference
swarm
.
Address
header
http
.
Header
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment