Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
cbor-gen
Commits
f6390fed
Commit
f6390fed
authored
Aug 04, 2020
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make ScanForLinks non-recursive
This way, we can't blow out our stack.
parent
cdf4113c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
52 deletions
+40
-52
utils.go
utils.go
+40
-52
No files found.
utils.go
View file @
f6390fed
...
@@ -17,11 +17,8 @@ const maxCidLength = 100
...
@@ -17,11 +17,8 @@ const maxCidLength = 100
const
maxHeaderSize
=
9
const
maxHeaderSize
=
9
func
ScanForLinks
(
br
io
.
Reader
,
cb
func
(
cid
.
Cid
))
error
{
func
ScanForLinks
(
br
io
.
Reader
,
cb
func
(
cid
.
Cid
))
error
{
buf
:=
make
([]
byte
,
maxCidLength
)
scratch
:=
make
([]
byte
,
maxCidLength
)
return
scanForLinksRec
(
br
,
cb
,
buf
)
for
remaining
:=
uint64
(
1
);
remaining
>
0
;
remaining
--
{
}
func
scanForLinksRec
(
br
io
.
Reader
,
cb
func
(
cid
.
Cid
),
scratch
[]
byte
)
error
{
maj
,
extra
,
err
:=
CborReadHeaderBuf
(
br
,
scratch
)
maj
,
extra
,
err
:=
CborReadHeaderBuf
(
br
,
scratch
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -60,25 +57,16 @@ func scanForLinksRec(br io.Reader, cb func(cid.Cid), scratch []byte) error {
...
@@ -60,25 +57,16 @@ func scanForLinksRec(br io.Reader, cb func(cid.Cid), scratch []byte) error {
cb
(
c
)
cb
(
c
)
}
else
{
}
else
{
if
err
:=
scanForLinksRec
(
br
,
cb
,
scratch
);
err
!=
nil
{
remaining
++
return
err
}
}
}
case
MajArray
:
case
MajArray
:
for
i
:=
0
;
i
<
int
(
extra
);
i
++
{
remaining
+=
extra
if
err
:=
scanForLinksRec
(
br
,
cb
,
scratch
);
err
!=
nil
{
return
err
}
}
case
MajMap
:
case
MajMap
:
for
i
:=
0
;
i
<
int
(
extra
*
2
);
i
++
{
remaining
+=
(
extra
*
2
)
if
err
:=
scanForLinksRec
(
br
,
cb
,
scratch
);
err
!=
nil
{
return
err
}
}
default
:
default
:
return
fmt
.
Errorf
(
"unhandled cbor type: %d"
,
maj
)
return
fmt
.
Errorf
(
"unhandled cbor type: %d"
,
maj
)
}
}
}
return
nil
return
nil
}
}
...
...
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