Skip to content

Commit 580c425

Browse files
committed
Revert "PLXCOMP-220: defensive checks to avoid passing negative uid/gid into TarEntry or encoding into tar output stream"
This reverts commit 1610239.
1 parent 3dfef37 commit 580c425

File tree

3 files changed

+19
-29
lines changed

3 files changed

+19
-29
lines changed

src/main/java/org/codehaus/plexus/archiver/tar/PosixTarEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ public void writeEntryHeader( byte[] outbuf )
121121

122122
offset = TarUtils.getNameBytes( this.name, outbuf, offset, NAMELEN );
123123
offset = TarUtils.getOctalBytes( this.mode, outbuf, offset, MODELEN );
124-
offset = TarUtils.getOctalBytes( ( this.userId >= 0 ? this.userId : 0 ), outbuf, offset, UIDLEN );
125-
offset = TarUtils.getOctalBytes( ( this.groupId >= 0 ? this.groupId : 0 ), outbuf, offset, GIDLEN );
124+
offset = TarUtils.getOctalBytes( this.userId, outbuf, offset, UIDLEN );
125+
offset = TarUtils.getOctalBytes( this.groupId, outbuf, offset, GIDLEN );
126126
offset = TarUtils.getLongOctalBytes( this.size, outbuf, offset, SIZELEN );
127127
offset = TarUtils.getLongOctalBytes( this.modTime, outbuf, offset, MODTIMELEN );
128128

src/main/java/org/codehaus/plexus/archiver/tar/TarArchiver.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
* limitations under the License.
1818
*/
1919

20+
import java.io.BufferedOutputStream;
21+
import java.io.File;
22+
import java.io.FileOutputStream;
23+
import java.io.IOException;
24+
import java.io.InputStream;
25+
import java.io.OutputStream;
26+
import java.util.zip.GZIPOutputStream;
27+
2028
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
2129
import org.codehaus.plexus.archiver.AbstractArchiver;
2230
import org.codehaus.plexus.archiver.ArchiveEntry;
@@ -30,14 +38,6 @@
3038
import org.codehaus.plexus.util.IOUtil;
3139
import org.codehaus.plexus.util.StringUtils;
3240

33-
import java.io.BufferedOutputStream;
34-
import java.io.File;
35-
import java.io.FileOutputStream;
36-
import java.io.IOException;
37-
import java.io.InputStream;
38-
import java.io.OutputStream;
39-
import java.util.zip.GZIPOutputStream;
40-
4141
/**
4242
* @author <a href="mailto:[email protected]">Emmanuel Venisse</a>
4343
* @version $Revision$ $Date$
@@ -249,7 +249,7 @@ protected void tarFile( ArchiveEntry entry, TarOutputStream tOut, String vPath )
249249
int pathLength = vPath.length();
250250
try
251251
{
252-
final TarEntry te;
252+
TarEntry te = null;
253253
if ( !longFileMode.isGnuMode() && pathLength >= TarConstants.NAMELEN )
254254
{
255255
int maxPosixPathLen = TarConstants.NAMELEN + TarConstants.POSIX_PREFIXLEN;
@@ -337,20 +337,10 @@ else if ( longFileMode.isFailMode() )
337337
: options.getUserName() );
338338
te.setGroupName( ( attributes != null && attributes.getGroupName() != null ) ? attributes.getGroupName()
339339
: options.getGroup() );
340-
341-
final int userId =
342-
( attributes != null && attributes.getUserId() != null ) ? attributes.getUserId() : options.getUid();
343-
if ( userId > 0 )
344-
{
345-
te.setUserId( userId );
346-
}
347-
348-
final int groupId =
349-
( attributes != null && attributes.getGroupId() != null ) ? attributes.getGroupId() : options.getGid();
350-
if ( groupId > 0 )
351-
{
352-
te.setGroupId( groupId );
353-
}
340+
te.setUserId( ( attributes != null && attributes.getUserId() != null) ? attributes.getUserId()
341+
: options.getUid() );
342+
te.setGroupId( ( attributes != null && attributes.getGroupId() != null) ? attributes.getGroupId()
343+
: options.getGid() );
354344

355345
tOut.putNextEntry( te );
356346

src/main/java/org/codehaus/plexus/archiver/tar/TarEntry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
* ([email protected]) to whom the Ant project is very grateful for his great code.
2323
*/
2424

25-
import org.codehaus.plexus.archiver.ArchiveFile;
26-
2725
import java.io.File;
2826
import java.util.Date;
2927
import java.util.Locale;
3028

29+
import org.codehaus.plexus.archiver.ArchiveFile;
30+
3131
/**
3232
* This class represents an entry in a Tar archive. It consists
3333
* of the entry's header, as well as the entry's File. Entries
@@ -670,8 +670,8 @@ public void writeEntryHeader( byte[] outbuf )
670670

671671
offset = TarUtils.getNameBytes( this.name, outbuf, offset, NAMELEN );
672672
offset = TarUtils.getOctalBytes( this.mode, outbuf, offset, MODELEN );
673-
offset = TarUtils.getOctalBytes( ( this.userId >= 0 ? this.userId : 0 ), outbuf, offset, UIDLEN );
674-
offset = TarUtils.getOctalBytes( ( this.groupId >= 0 ? this.groupId : 0 ), outbuf, offset, GIDLEN );
673+
offset = TarUtils.getOctalBytes( this.userId, outbuf, offset, UIDLEN );
674+
offset = TarUtils.getOctalBytes( this.groupId, outbuf, offset, GIDLEN );
675675
offset = TarUtils.getLongOctalBytes( this.size, outbuf, offset, SIZELEN );
676676
offset = TarUtils.getLongOctalBytes( this.modTime, outbuf, offset, MODTIMELEN );
677677

0 commit comments

Comments
 (0)