Skip to content
Snippets Groups Projects
Commit 4aa94542 authored by Ann Priestman's avatar Ann Priestman
Browse files

Test that the image handle is still valid before using it.

parent 12a3be88
No related branches found
No related tags found
No related merge requests found
......@@ -643,6 +643,9 @@ private static long openImage(String[] imageFiles, int sSize, boolean useCache)
public static long openVs(long imgHandle, long vsOffset) throws TskCoreException {
getTSKReadLock();
try {
if(! imgHandleIsValid(imgHandle)) {
throw new TskCoreException("Image handle " + imgHandle + " is closed");
}
return openVsNat(imgHandle, vsOffset);
} finally {
releaseTSKReadLock();
......@@ -756,6 +759,17 @@ private static int convertSignedToUnsigned(int val) {
return val & 0xffff; // convert negative value to positive value
}
/**
* Test that the given image handle is valid.
* @param imgHandle
* @return true if it is valid, false otherwise
*/
private static boolean imgHandleIsValid(long imgHandle) {
synchronized(HandleCache.cacheLock) {
return HandleCache.fsHandleCache.containsKey(imgHandle);
}
}
//do reads
/**
......@@ -775,6 +789,9 @@ private static int convertSignedToUnsigned(int val) {
public static int readImg(long imgHandle, byte[] readBuffer, long offset, long len) throws TskCoreException {
getTSKReadLock();
try {
if(! imgHandleIsValid(imgHandle)) {
throw new TskCoreException("Image handle " + imgHandle + " is closed");
}
//returned byte[] is the data buffer
return readImgNat(imgHandle, readBuffer, offset, len);
} finally {
......@@ -1226,6 +1243,9 @@ private static String timezoneLongToShort(String timezoneLongForm) {
public static int finishImageWriter(long imgHandle) throws TskCoreException {
getTSKReadLock();
try {
if(! imgHandleIsValid(imgHandle)) {
throw new TskCoreException("Image handle " + imgHandle + " is closed");
}
return finishImageWriterNat(imgHandle);
} finally {
releaseTSKReadLock();
......@@ -1242,7 +1262,11 @@ public static int finishImageWriter(long imgHandle) throws TskCoreException {
public static int getFinishImageProgress(long imgHandle) {
getTSKReadLock();
try {
return getFinishImageProgressNat(imgHandle);
if (imgHandleIsValid(imgHandle)) {
return getFinishImageProgressNat(imgHandle);
} else {
return 0;
}
} finally {
releaseTSKReadLock();
}
......@@ -1256,7 +1280,9 @@ public static int getFinishImageProgress(long imgHandle) {
public static void cancelFinishImage(long imgHandle) {
getTSKReadLock();
try {
cancelFinishImageNat(imgHandle);
if (imgHandleIsValid(imgHandle)) {
cancelFinishImageNat(imgHandle);
}
} finally {
releaseTSKReadLock();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment