Updated the convert from bytes method to validate the input parameters before processing

This commit is contained in:
almondkiruthu 2023-04-12 22:05:06 +03:00
parent 138bb51997
commit 723af2394c
6 changed files with 47 additions and 6 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

6
.idea/misc.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/the-algorithm.iml" filepath="$PROJECT_DIR$/.idea/the-algorithm.iml" />
</modules>
</component>
</project>

9
.idea/the-algorithm.iml Normal file
View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -25,10 +25,14 @@ public final class CSFTypeUtil {
return 0;
}
int offset = startOffset + valueIndex * Integer.BYTES;
return ((data[offset] & 0xFF) << 24)
| ((data[offset + 1] & 0xFF) << 16)
| ((data[offset + 2] & 0xFF) << 8)
| (data[offset + 3] & 0xFF);
// Validate input parameters
if (startOffset < 0 || valueIndex < 0 || startOffset + valueIndex * Integer.BYTES > data.length) {
throw new IllegalArgumentException("Invalid input parameters");
}
final int offset = startOffset + valueIndex * Integer.BYTES;
final ByteBuffer buffer = ByteBuffer.wrap(data, offset, Integer.BYTES).order(ByteOrder.BIG_ENDIAN);
return buffer.getInt();
}
}