Function bodies 3,594 total
DiskFileItem method · java · L189-L198 (10 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public DiskFileItem(String fieldName,
String contentType, boolean isFormField, String fileName,
int sizeThreshold, File repository) {
this.fieldName = fieldName;
this.contentType = contentType;
this.isFormField = isFormField;
this.fileName = fileName;
this.sizeThreshold = sizeThreshold;
this.repository = repository;
}getInputStream method · java · L211-L221 (11 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public InputStream getInputStream()
throws IOException {
if (!isInMemory()) {
return new FileInputStream(dfos.getFile());
}
if (cachedContent == null) {
cachedContent = dfos.getData();
}
return new ByteArrayInputStream(cachedContent);
}getContentType method · java · L230-L232 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public String getContentType() {
return contentType;
}getCharSet method · java · L241-L247 (7 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public String getCharSet() {
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
Map<String, String> params = parser.parse(getContentType(), ';');
return params.get("charset");
}getName method · java · L258-L260 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public String getName() {
return Streams.checkFileName(fileName);
}isInMemory method · java · L271-L276 (6 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public boolean isInMemory() {
if (cachedContent != null) {
return true;
}
return dfos.isInMemory();
}getSize method · java · L283-L293 (11 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public long getSize() {
if (size >= 0) {
return size;
} else if (cachedContent != null) {
return cachedContent.length;
} else if (dfos.isInMemory()) {
return dfos.getData().length;
} else {
return dfos.getFile().length();
}
}About: code-quality intelligence by Repobility · https://repobility.com
get method · java · L302-L329 (28 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public byte[] get() {
if (isInMemory()) {
if (cachedContent == null) {
cachedContent = dfos.getData();
}
return cachedContent;
}
byte[] fileData = new byte[(int) getSize()];
InputStream fis = null;
try {
fis = new BufferedInputStream(new FileInputStream(dfos.getFile()));
fis.read(fileData);
} catch (IOException e) {
fileData = null;
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
// ignore
}
}
}
return fileData;
}getString method · java · L343-L346 (4 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public String getString(final String charset)
throws UnsupportedEncodingException {
return new String(get(), charset);
}getString method · java · L357-L368 (12 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public String getString() {
byte[] rawdata = get();
String charset = getCharSet();
if (charset == null) {
charset = DEFAULT_CHARSET;
}
try {
return new String(rawdata, charset);
} catch (UnsupportedEncodingException e) {
return new String(rawdata);
}
}write method · java · L390-L446 (57 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public void write(File file) throws Exception {
if (isInMemory()) {
FileOutputStream fout = null;
try {
fout = new FileOutputStream(file);
fout.write(get());
} finally {
if (fout != null) {
fout.close();
}
}
} else {
File outputFile = getStoreLocation();
if (outputFile != null) {
// Save the length of the file
size = outputFile.length();
/*
* The uploaded file is being stored on disk
* in a temporary location so move it to the
* desired file.
*/
if (!outputFile.renameTo(file)) {
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(
delete method · java · L455-L461 (7 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public void delete() {
cachedContent = null;
File outputFile = getStoreLocation();
if (outputFile != null && outputFile.exists()) {
outputFile.delete();
}
}getFieldName method · java · L472-L474 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public String getFieldName() {
return fieldName;
}setFieldName method · java · L484-L486 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}isFormField method · java · L498-L500 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public boolean isFormField() {
return isFormField;
}Repobility — the code-quality scanner for AI-generated software · https://repobility.com
setFormField method · java · L512-L514 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public void setFormField(boolean state) {
isFormField = state;
}getOutputStream method · java · L525-L532 (8 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public OutputStream getOutputStream()
throws IOException {
if (dfos == null) {
File outputFile = getTempFile();
dfos = new DeferredFileOutputStream(sizeThreshold, outputFile);
}
return dfos;
}getStoreLocation method · java · L549-L554 (6 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public File getStoreLocation() {
if (dfos == null) {
return null;
}
return dfos.getFile();
}finalize method · java · L562-L568 (7 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
protected void finalize() {
File outputFile = dfos.getFile();
if (outputFile != null && outputFile.exists()) {
outputFile.delete();
}
}getTempFile method · java · L578-L590 (13 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
protected File getTempFile() {
if (tempFile == null) {
File tempDir = repository;
if (tempDir == null) {
tempDir = new File(System.getProperty("java.io.tmpdir"));
}
String tempFileName = format("upload_%s_%s.tmp", UID, getUniqueId());
tempFile = new File(tempDir, tempFileName);
}
return tempFile;
}getUniqueId method · java · L600-L611 (12 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
private static String getUniqueId() {
final int limit = 100000000;
int current = COUNTER.getAndIncrement();
String id = Integer.toString(current);
// If you manage to get more than 100 million of ids, you'll
// start getting ids longer than 8 characters.
if (current < limit) {
id = ("00000000" + id).substring(id.length());
}
return id;
}toString method · java · L619-L622 (4 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public String toString() {
return format("name=%s, StoreLocation=%s, size=%s bytes, isFormField=%s, FieldName=%s",
getName(), getStoreLocation(), getSize(), isFormField(), getFieldName());
}writeObject method · java · L633-L644 (12 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
private void writeObject(ObjectOutputStream out) throws IOException {
// Read the data
if (dfos.isInMemory()) {
cachedContent = get();
} else {
cachedContent = null;
dfosFile = dfos.getFile();
}
// write out values
out.defaultWriteObject();
}Repobility · code-quality intelligence platform · https://repobility.com
readObject method · java · L654-L691 (38 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
// read values
in.defaultReadObject();
/* One expected use of serialization is to migrate HTTP sessions
* containing a DiskFileItem between JVMs. Particularly if the JVMs are
* on different machines It is possible that the repository location is
* not valid so validate it.
*/
if (repository != null) {
if (repository.isDirectory()) {
// Check path for nulls
if (repository.getPath().contains("\0")) {
throw new IOException(format(
"The repository [%s] contains a null character",
repository.getPath()));
}
} else {
throw new IOException(format(
"The repository [%s] is not a directory",
repository.getAbsolutePagetHeaders method · java · L697-L699 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public FileItemHeaders getHeaders() {
return headers;
}setHeaders method · java · L705-L707 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/fixed/DiskFileItem.java
public void setHeaders(FileItemHeaders pHeaders) {
headers = pHeaders;
}DiskFileItem method · java · L189-L198 (10 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public DiskFileItem(String fieldName,
String contentType, boolean isFormField, String fileName,
int sizeThreshold, File repository) {
this.fieldName = fieldName;
this.contentType = contentType;
this.isFormField = isFormField;
this.fileName = fileName;
this.sizeThreshold = sizeThreshold;
this.repository = repository;
}getInputStream method · java · L211-L221 (11 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public InputStream getInputStream()
throws IOException {
if (!isInMemory()) {
return new FileInputStream(dfos.getFile());
}
if (cachedContent == null) {
cachedContent = dfos.getData();
}
return new ByteArrayInputStream(cachedContent);
}getContentType method · java · L230-L232 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public String getContentType() {
return contentType;
}getCharSet method · java · L241-L247 (7 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public String getCharSet() {
ParameterParser parser = new ParameterParser();
parser.setLowerCaseNames(true);
// Parameter parser can handle null input
Map<String, String> params = parser.parse(getContentType(), ';');
return params.get("charset");
}getName method · java · L258-L260 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public String getName() {
return Streams.checkFileName(fileName);
}Provenance: Repobility (https://repobility.com) — every score reproducible from /scan/
isInMemory method · java · L271-L276 (6 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public boolean isInMemory() {
if (cachedContent != null) {
return true;
}
return dfos.isInMemory();
}getSize method · java · L283-L293 (11 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public long getSize() {
if (size >= 0) {
return size;
} else if (cachedContent != null) {
return cachedContent.length;
} else if (dfos.isInMemory()) {
return dfos.getData().length;
} else {
return dfos.getFile().length();
}
}get method · java · L302-L329 (28 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public byte[] get() {
if (isInMemory()) {
if (cachedContent == null) {
cachedContent = dfos.getData();
}
return cachedContent;
}
byte[] fileData = new byte[(int) getSize()];
InputStream fis = null;
try {
fis = new BufferedInputStream(new FileInputStream(dfos.getFile()));
fis.read(fileData);
} catch (IOException e) {
fileData = null;
} finally {
if (fis != null) {
try {
fis.close();
} catch (IOException e) {
// ignore
}
}
}
return fileData;
}getString method · java · L343-L346 (4 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public String getString(final String charset)
throws UnsupportedEncodingException {
return new String(get(), charset);
}getString method · java · L357-L368 (12 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public String getString() {
byte[] rawdata = get();
String charset = getCharSet();
if (charset == null) {
charset = DEFAULT_CHARSET;
}
try {
return new String(rawdata, charset);
} catch (UnsupportedEncodingException e) {
return new String(rawdata);
}
}write method · java · L390-L446 (57 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public void write(File file) throws Exception {
if (isInMemory()) {
FileOutputStream fout = null;
try {
fout = new FileOutputStream(file);
fout.write(get());
} finally {
if (fout != null) {
fout.close();
}
}
} else {
File outputFile = getStoreLocation();
if (outputFile != null) {
// Save the length of the file
size = outputFile.length();
/*
* The uploaded file is being stored on disk
* in a temporary location so move it to the
* desired file.
*/
if (!outputFile.renameTo(file)) {
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(
delete method · java · L455-L461 (7 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public void delete() {
cachedContent = null;
File outputFile = getStoreLocation();
if (outputFile != null && outputFile.exists()) {
outputFile.delete();
}
}getFieldName method · java · L472-L474 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public String getFieldName() {
return fieldName;
}About: code-quality intelligence by Repobility · https://repobility.com
setFieldName method · java · L484-L486 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}isFormField method · java · L498-L500 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public boolean isFormField() {
return isFormField;
}setFormField method · java · L512-L514 (3 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public void setFormField(boolean state) {
isFormField = state;
}getOutputStream method · java · L525-L532 (8 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public OutputStream getOutputStream()
throws IOException {
if (dfos == null) {
File outputFile = getTempFile();
dfos = new DeferredFileOutputStream(sizeThreshold, outputFile);
}
return dfos;
}getStoreLocation method · java · L549-L554 (6 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public File getStoreLocation() {
if (dfos == null) {
return null;
}
return dfos.getFile();
}finalize method · java · L562-L568 (7 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
protected void finalize() {
File outputFile = dfos.getFile();
if (outputFile != null && outputFile.exists()) {
outputFile.delete();
}
}getTempFile method · java · L578-L590 (13 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
protected File getTempFile() {
if (tempFile == null) {
File tempDir = repository;
if (tempDir == null) {
tempDir = new File(System.getProperty("java.io.tmpdir"));
}
String tempFileName = format("upload_%s_%s.tmp", UID, getUniqueId());
tempFile = new File(tempDir, tempFileName);
}
return tempFile;
}getUniqueId method · java · L600-L611 (12 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
private static String getUniqueId() {
final int limit = 100000000;
int current = COUNTER.getAndIncrement();
String id = Integer.toString(current);
// If you manage to get more than 100 million of ids, you'll
// start getting ids longer than 8 characters.
if (current < limit) {
id = ("00000000" + id).substring(id.length());
}
return id;
}Repobility — the code-quality scanner for AI-generated software · https://repobility.com
toString method · java · L619-L622 (4 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
public String toString() {
return format("name=%s, StoreLocation=%s, size=%s bytes, isFormField=%s, FieldName=%s",
getName(), getStoreLocation(), getSize(), isFormField(), getFieldName());
}writeObject method · java · L633-L644 (12 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
private void writeObject(ObjectOutputStream out) throws IOException {
// Read the data
if (dfos.isInMemory()) {
cachedContent = get();
} else {
cachedContent = null;
dfosFile = dfos.getFile();
}
// write out values
out.defaultWriteObject();
}readObject method · java · L654-L671 (18 LOC)data/dim2b/scenarios/vul4j-10-cwe20/vulnerable/DiskFileItem.java
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
// read values
in.defaultReadObject();
OutputStream output = getOutputStream();
if (cachedContent != null) {
output.write(cachedContent);
} else {
FileInputStream input = new FileInputStream(dfosFile);
IOUtils.copy(input, output);
dfosFile.delete();
dfosFile = null;
}
output.close();
cachedContent = null;
}page 1 / 72next ›