Skip to content

Commit

Permalink
do not add outgoing group file to message history if shrinking failed…
Browse files Browse the repository at this point in the history
…. also set a general limit at 100MByte for processing a group file
  • Loading branch information
zoff99 committed Mar 25, 2024
1 parent f6dc527 commit 83463b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/zoffcc/applications/trifa/ToxVars.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class ToxVars
public static final int TOX_MSGV3_GUARD = 2;
public static final int TOX_MSGV3_MAX_MESSAGE_LENGTH = (TOX_MAX_MESSAGE_LENGTH - TOX_MSGV3_MSGID_LENGTH - TOX_MSGV3_TIMESTAMP_LENGTH - TOX_MSGV3_GUARD);

public static final int TOX_MAX_NGC_FILESIZE_IGNORE_OVER_THAT = 100 * 1014 * 1024; // do not process anything about 100 MByte
public static final int TOX_MAX_NGC_FILESIZE = 36701;
public static final int TOX_MAX_NGC_FILE_AND_HEADER_SIZE = 37000;
// TODO: get these with the appropriate JNI functions!
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/com/zoffcc/applications/trifa/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ import com.zoffcc.applications.trifa.ToxVars.TOX_CONNECTION
import com.zoffcc.applications.trifa.ToxVars.TOX_FILE_ID_LENGTH
import com.zoffcc.applications.trifa.ToxVars.TOX_HASH_LENGTH
import com.zoffcc.applications.trifa.ToxVars.TOX_MAX_NGC_FILESIZE
import com.zoffcc.applications.trifa.ToxVars.TOX_MAX_NGC_FILESIZE_IGNORE_OVER_THAT
import com.zoffcc.applications.trifa.ToxVars.TOX_MAX_NGC_FILE_AND_HEADER_SIZE
import com.zoffcc.applications.trifa.ToxVars.TOX_PUBLIC_KEY_SIZE
import com.zoffcc.applications.trifa.TrifaToxService.Companion.orma
Expand Down Expand Up @@ -3764,13 +3765,26 @@ class MainActivity
ofw.filepath_wrapped = filepath
ofw.filename_wrapped = filename

if (file_size > TOX_MAX_NGC_FILESIZE_IGNORE_OVER_THAT)
{
Log.i(TAG, "add_outgoing_file:too large to process, size=" + ofw.file_size_wrapped)
SnackBarToast("Error sending file to group, file is too large to process")
return
}

if (file_size > TOX_MAX_NGC_FILESIZE)
{
// reducing the file size down to hopefully 37kbytes -------------------
Log.i(TAG, "add_outgoing_file:shrink:start")
ofw = shrink_image_file(ofw, groupid)
Log.i(TAG, "add_outgoing_file:shrink:done:")
// reducing the file size down to hopefully 37kbytes -------------------
if (ofw.file_size_wrapped > TOX_MAX_NGC_FILESIZE)
{
Log.i(TAG, "add_outgoing_file:failed to shrink file, size=" + ofw.file_size_wrapped)
SnackBarToast("Error sending file to group, failed to shrink to allowed size")
return
}
}
else
{
Expand Down

0 comments on commit 83463b3

Please sign in to comment.