Skip to content
This repository was archived by the owner on Jan 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
95d56fa
Fix: Refactored the code to merge two if conditions into a single con…
meet0208 Oct 3, 2024
9f37596
Merge pull request #2 from rajbhensdadiya/fix/dev_meet
meet0208 Oct 3, 2024
d3c4e1d
Defined a constant instead of duplicating this literal “Failed to ass…
MariyaBosy Oct 9, 2024
8b17ba4
Merge branch 'rilling:master' into dev_maria
MariyaBosy Oct 9, 2024
44949e3
Refactored onTouch method to replace anonymous inner class with a lam…
kawsarahmedbhuiyan Oct 12, 2024
e71e5f7
Merge if statement with the enclosing one
rajbhensdadiya Oct 12, 2024
48ccee0
Merge pull request #3 from rajbhensdadiya/dev_maria
MariyaBosy Oct 14, 2024
70eb931
Refactored the code to remove usage of multiple deprecated methods.
SahebChandok Oct 14, 2024
58b0818
Merge branch 'rilling:master' into master
rajbhensdadiya Nov 7, 2024
bcf6498
Refactor: Remove duplicate onTouch method logic in AndroidInputHandle…
rajbhensdadiya Nov 7, 2024
10a3a54
Fix: Refactor TouchEvent setup to remove duplicate code in onShowPres…
meet0208 Nov 7, 2024
56f1426
Merge pull request #13 from rajbhensdadiya/fix/dev_refactor_meet
meet0208 Nov 7, 2024
d23dedf
Refactor: Remove duplicate onKey method.
MariyaBosy Nov 9, 2024
5de3ea6
Merge pull request #12 from rajbhensdadiya/refactor/onTouch-clone-rem…
meet0208 Nov 9, 2024
1c8ffdc
Refactored duplicated file descriptor handling in loadBuffer and load…
kawsarahmedbhuiyan Nov 10, 2024
38a8fce
Merge pull request #14 from rajbhensdadiya/pmd_dev_maria
rajbhensdadiya Nov 10, 2024
98febfa
Merge pull request #15 from rajbhensdadiya/refactor/dev_kawsar
rajbhensdadiya Nov 10, 2024
85fabc4
Refactor OpenGL error handling to remove code duplication
SahebChandok Nov 11, 2024
ca0448e
Merge pull request #16 from rajbhensdadiya/fix/dev_refactor_saheb
rajbhensdadiya Nov 11, 2024
ab0a6e3
Fix: removed conflict
meet0208 Nov 24, 2024
7922ef5
Fix: removed the Cleartext Transmission of Sensitive Information vuln…
meet0208 Nov 26, 2024
de8f8d2
Merge pull request #18 from rajbhensdadiya/fix/dev_vulnerability_meet
meet0208 Nov 26, 2024
0f5e82c
Fixed Path Traversal Vulnerability
SahebChandok Nov 28, 2024
5a6fde8
Fixed Improper Restriction of XML External Entity Reference Vulnerabi…
kawsarahmedbhuiyan Nov 29, 2024
a4cec01
Revert "Fixed Path Traversal Vulnerability"
SahebChandok Nov 29, 2024
1313e14
Merge pull request #20 from rajbhensdadiya/fix-vulnerability/dev_kawsar
rajbhensdadiya Nov 29, 2024
34ca959
Merge branch 'master' of https://github.com/rajbhensdadiya/jmonkeyeng…
SahebChandok Nov 29, 2024
e89072e
Optimize regex to prevent ReDoS vulnerability by reducing backtracking
SahebChandok Nov 29, 2024
990f334
Merge pull request #21 from rajbhensdadiya/fix/dev_vulnerability_saheb
meet0208 Dec 1, 2024
dd598d7
fix: secure FileOutputStream with encryption in MjpegFileWriter
rajbhensdadiya Dec 1, 2024
0da216b
Merge pull request #22 from rajbhensdadiya/raj/dev_vulnerability
rajbhensdadiya Dec 1, 2024
6a564db
Fix vulnerability in executeAnalyzer to enhance security and handle f…
MariyaBosy Dec 2, 2024
dd3a8c6
Merge pull request #23 from rajbhensdadiya/dev_soft_vulnerability_maria
meet0208 Dec 2, 2024
2b9020b
fix: merge conflicts
Dec 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 51 additions & 25 deletions jme3-android/src/main/java/com/jme3/app/state/MjpegFileWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
*/
package com.jme3.app.state;

import android.graphics.Bitmap;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
Expand All @@ -43,19 +42,28 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.crypto.Cipher;
import javax.crypto.CipherOutputStream;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

import android.graphics.Bitmap;

/**
* Released under BSD License
* @author monceaux, normenhansen, entrusC
*/
public class MjpegFileWriter {
private static final Logger logger = Logger.getLogger(MjpegFileWriter.class.getName());
private static final String ENCRYPTION_ALGORITHM = "AES";
private static final byte[] KEY = "YourSecretKey123".getBytes();

int width = 0;
int height = 0;
double framerate = 0;
int numFrames = 0;
File aviFile = null;
FileOutputStream aviOutput = null;
CipherOutputStream encryptedOutput = null;
FileChannel aviChannel = null;
long riffOffset = 0;
long aviMovieOffset = 0;
Expand All @@ -71,18 +79,29 @@ public MjpegFileWriter(File aviFile, int width, int height, double framerate, in
this.height = height;
this.framerate = framerate;
this.numFrames = numFrames;
aviOutput = new FileOutputStream(aviFile);
aviChannel = aviOutput.getChannel();

SecretKey secretKey = new SecretKeySpec(KEY, ENCRYPTION_ALGORITHM);
Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);

FileOutputStream fileOut = new FileOutputStream(aviFile) {
@Override
public FileChannel getChannel() {
return super.getChannel();
}
};
encryptedOutput = new CipherOutputStream(fileOut, cipher);
aviChannel = fileOut.getChannel();

RIFFHeader rh = new RIFFHeader();
aviOutput.write(rh.toBytes());
aviOutput.write(new AVIMainHeader().toBytes());
aviOutput.write(new AVIStreamList().toBytes());
aviOutput.write(new AVIStreamHeader().toBytes());
aviOutput.write(new AVIStreamFormat().toBytes());
aviOutput.write(new AVIJunk().toBytes());
encryptedOutput.write(rh.toBytes());
encryptedOutput.write(new AVIMainHeader().toBytes());
encryptedOutput.write(new AVIStreamList().toBytes());
encryptedOutput.write(new AVIStreamHeader().toBytes());
encryptedOutput.write(new AVIStreamFormat().toBytes());
encryptedOutput.write(new AVIJunk().toBytes());
aviMovieOffset = aviChannel.position();
aviOutput.write(new AVIMovieList().toBytes());
encryptedOutput.write(new AVIMovieList().toBytes());
indexlist = new AVIIndexList();
}

Expand All @@ -105,12 +124,12 @@ public void addImage(byte[] imagedata) throws Exception {

indexlist.addAVIIndex((int) position, useLength);

aviOutput.write(fcc);
aviOutput.write(intBytes(swapInt(useLength)));
aviOutput.write(imagedata);
encryptedOutput.write(fcc);
encryptedOutput.write(intBytes(swapInt(useLength)));
encryptedOutput.write(imagedata);
if (extra > 0) {
for (int i = 0; i < extra; i++) {
aviOutput.write(0);
encryptedOutput.write(0);
}
}

Expand All @@ -120,8 +139,13 @@ public void addImage(byte[] imagedata) throws Exception {
public void finishAVI() throws Exception {
logger.log(Level.INFO, "finishAVI");
byte[] indexlistBytes = indexlist.toBytes();
aviOutput.write(indexlistBytes);
aviOutput.close();
encryptedOutput.write(indexlistBytes);
encryptedOutput.close();

SecretKey secretKey = new SecretKeySpec(KEY, ENCRYPTION_ALGORITHM);
Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);

int fileSize = (int)aviFile.length();
logger.log(Level.INFO, "fileSize: {0}", fileSize);
int listSize = (int) (fileSize - 8 - aviMovieOffset - indexlistBytes.length);
Expand All @@ -133,17 +157,19 @@ public void finishAVI() throws Exception {
}

RandomAccessFile raf = new RandomAccessFile(aviFile, "rw");
CipherOutputStream headerUpdate = new CipherOutputStream(new FileOutputStream(raf.getFD()), cipher);

//add header and length by writing the headers again
//with the now available information
raf.write(new RIFFHeader(fileSize).toBytes());
raf.write(new AVIMainHeader().toBytes());
raf.write(new AVIStreamList().toBytes());
raf.write(new AVIStreamHeader().toBytes());
raf.write(new AVIStreamFormat().toBytes());
raf.write(new AVIJunk().toBytes());
raf.write(new AVIMovieList(listSize).toBytes());

headerUpdate.write(new RIFFHeader(fileSize).toBytes());
headerUpdate.write(new AVIMainHeader().toBytes());
headerUpdate.write(new AVIStreamList().toBytes());
headerUpdate.write(new AVIStreamHeader().toBytes());
headerUpdate.write(new AVIStreamFormat().toBytes());
headerUpdate.write(new AVIJunk().toBytes());
headerUpdate.write(new AVIMovieList(listSize).toBytes());

headerUpdate.close();
raf.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,14 @@ protected boolean processTouchEvent(View view, MotionEvent event) {
public boolean onTouch(View view, MotionEvent event) {
return processTouchEvent(view, event);
}

protected boolean consumeEvent(KeyEvent event, Object touchInput, Object joyInput) {
int source = event.getSource();

boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN)
|| ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD);
boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) ||
((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD);

boolean isJoystick = ((source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
|| ((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK);
boolean isJoystick = ((source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK);

boolean isUnknown = (source & InputDevice.SOURCE_UNKNOWN) == InputDevice.SOURCE_UNKNOWN;

Expand All @@ -201,7 +200,7 @@ protected boolean consumeEvent(KeyEvent event, Object touchInput, Object joyInpu

// Check if joyInput should consume the event
if (isJoystick && joyInput != null) {
consumed |= ((AndroidJoyInput14) joyInput).onKey(event);
consumed |= ((AndroidJoyInput14)joyInput).onKey(event);
}

return consumed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public final class GLRenderer implements Renderer {

private static final Logger logger = Logger.getLogger(GLRenderer.class.getName());
private static final boolean VALIDATE_SHADER = false;
private static final Pattern GLVERSION_PATTERN = Pattern.compile(".*?(\\d+)\\.(\\d+).*");
private static final Pattern GLVERSION_PATTERN = Pattern.compile("\\b(\\d+)\\.(\\d+)\\b");

private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250);
private final FloatBuffer floatBuf16 = BufferUtils.createFloatBuffer(16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,59 +54,73 @@ public String getInstalledVersion() {
}
return version;
}
private static void executeAnalyzer(String sourceCode, String language, String defines, String asic, StringBuilder results){
private static void executeAnalyzer(String sourceCode, String language, String defines, String asic, StringBuilder results) {
try {
// Export sourcecode to temporary file
File tempFile = File.createTempFile("test_shader", ".glsl");
FileWriter writer = new FileWriter(tempFile);

String glslVer = language.substring(4);
writer.append("#version ").append(glslVer).append('\n');
writer.append("#extension all : warn").append('\n');
writer.append(defines).append('\n');
writer.write(sourceCode);
writer.close();

ProcessBuilder pb = new ProcessBuilder("GPUShaderAnalyzer",
tempFile.getAbsolutePath(),
"-I",
"-ASIC", asic);

Process p = pb.start();

Scanner scan = new Scanner(p.getInputStream());

if (!scan.hasNextLine()){
String x = scan.next();
System.out.println(x);
// Export source code to a secure temporary file
File tempFile = File.createTempFile("test_shader", ".glsl", new File(System.getProperty("java.io.tmpdir")));

// Set secure file permissions and validate results
if (!tempFile.setReadable(false, false)) {
logger.log(Level.WARNING, "Failed to set temp file as non-readable for others: {0}", tempFile.getAbsolutePath());
}

String ln = scan.nextLine();

if (ln.startsWith(";")){
results.append(" - Success!").append('\n');
}else{
results.append(" - Failure!").append('\n');
results.append(ln).append('\n');
while (scan.hasNextLine()){
results.append(scan.nextLine()).append('\n');
}
if (!tempFile.setWritable(true, true)) {
logger.log(Level.WARNING, "Failed to set temp file as writable for the owner: {0}", tempFile.getAbsolutePath());
}
if (!tempFile.setExecutable(false, false)) {
logger.log(Level.WARNING, "Failed to disable execute permissions on temp file: {0}", tempFile.getAbsolutePath());
}

scan.close();
try (FileWriter writer = new FileWriter(tempFile)) {
String glslVer = language.substring(4);
writer.append("#version ").append(glslVer).append('\n');
writer.append("#extension all : warn").append('\n');
writer.append(defines).append('\n');
writer.write(sourceCode);
}

ProcessBuilder pb = new ProcessBuilder("GPUShaderAnalyzer",
tempFile.getAbsolutePath(),
"-I",
"-ASIC", asic);

Process p = pb.start();

try (Scanner scan = new Scanner(p.getInputStream())) {
if (!scan.hasNextLine()) {
String x = scan.next();
System.out.println(x);
}

String ln = scan.nextLine();

if (ln.startsWith(";")) {
results.append(" - Success!").append('\n');
} else {
results.append(" - Failure!").append('\n');
results.append(ln).append('\n');
while (scan.hasNextLine()) {
results.append(scan.nextLine()).append('\n');
}
}
}

p.getOutputStream().close();
p.getErrorStream().close();

p.waitFor();
p.destroy();

tempFile.delete();

// Delete the temporary file securely
if (!tempFile.delete()) {
logger.log(Level.WARNING, "Temporary file could not be deleted: {0}", tempFile.getAbsolutePath());
}
} catch (InterruptedException ex) {
Thread.currentThread().interrupt(); // Restore the interrupted status
} catch (IOException ex) {
logger.log(Level.SEVERE, "IOEx", ex);
logger.log(Level.SEVERE, "IOException occurred", ex);
}
}

@Override
public void validate(Shader shader, StringBuilder results) {
for (ShaderSource source : shader.getSources()){
Expand All @@ -121,5 +135,5 @@ public void validate(Shader shader, StringBuilder results) {
}
}
}

}
Loading
Loading