Skip to content

Commit

Permalink
Directory entries should have 0 size
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 8, 2017
1 parent 4bfd57b commit 3c70b5d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class Header {
if (this[TYPE] === '0' && this.path.substr(-1) === '/')
this[TYPE] = '5'

// tar implementations sometimes incorrectly put the stat(dir).size
// as the size in the tarball, even though Directory entries are
// not able to have any body at all. In the very rare chance that
// it actually DOES have a body, we weren't going to do anything with
// it anyway, and it'll just be a warning about an invalid header.
if (this[TYPE] === '5')
this.size = 0

this.linkpath = decString(buf, off + 157, 100)
if (buf.slice(off + 257, off + 265).toString() === 'ustar\u000000') {
this.uname = decString(buf, off + 265, 32)
Expand Down
25 changes: 25 additions & 0 deletions test/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,28 @@ t.test('big numbers', t => {
t.equal(h2.size, 0o77777777777 + 1)
t.end()
})

t.test('dir with long body', t => {
const b = new Buffer(
'7061636b6167652f76656e646f72000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000030303037353520003030303030302000303030303030200030303030' +
'3030313030303020313330363133303232343120303132303236200035000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0075737461720030300000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000003030303030302000303030303030200000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000' +
'0000000000000000000000000000000000000000000000000000000000000000',
'hex')
const h = new Header(b)
t.equal(h.type, 'Directory')
t.equal(h.size, 0)
t.end()
})

0 comments on commit 3c70b5d

Please sign in to comment.