Skip to content

Commit b5ab45d

Browse files
lgritz1div0
authored andcommitted
Internals: various fixes for memory safey and reduce static analysis complaints (AcademySoftwareFoundation#4128)
* jpeg output: Extra memory check * TS: batch texture call fixed to handle any number of channels * TS: assert to guard against possible null pointer dereference * oiiotool printinfo: clarify assertion for the sake of static analysis * jpeg2000 reader: assertion to ensure we don't dereference a null pointer Signed-off-by: Larry Gritz <[email protected]> Signed-off-by: Peter Kovář <[email protected]>
1 parent a51518a commit b5ab45d

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

.github/workflows/analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ jobs:
126126
echo "BUILD_OUTPUT_DIR is " "${{ env.BUILD_WRAPPER_OUT_DIR }}"
127127
find . -name "*.gcov" -print
128128
# sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
129-
sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="$BUILD_WRAPPER_OUT_DIR" --define sonar.cfamily.gcov.reportsPath="_coverage" --define sonar.cfamily.threads="$PARALLEL"
129+
time sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="$BUILD_WRAPPER_OUT_DIR" --define sonar.cfamily.gcov.reportsPath="_coverage" --define sonar.cfamily.threads="$PARALLEL"
130130
# Consult https://docs.sonarcloud.io/advanced-setup/ci-based-analysis/sonarscanner-cli/ for more information and options
131131

132132
# - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0

src/jpeg.imageio/jpegoutput.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ JpgOutput::open(const std::string& name, const ImageSpec& newspec,
306306
profile[11] = 0;
307307
profile[12] = curr_marker;
308308
profile[13] = (JOCTET)num_markers;
309+
OIIO_ASSERT(profile_size >= ICC_HEADER_SIZE + length);
309310
memcpy(profile.data() + ICC_HEADER_SIZE,
310311
icc_profile + length * (curr_marker - 1),
311312
length); //NOSONAR

src/jpeg2000.imageio/jpeg2000input.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ Jpeg2000Input::open(const std::string& name, ImageSpec& p_spec)
275275
close();
276276
return false;
277277
}
278+
OIIO_ASSERT(m_image != nullptr);
278279

279280
// we support only one, three or four components in image
280281
const int channelCount = m_image->numcomps;

src/libtexture/texturesys.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,8 +1350,10 @@ TextureSystemImpl::texture(TextureHandle* texture_handle,
13501350

13511351
bool ok = true;
13521352
Tex::RunMask bit = 1;
1353+
float* r = OIIO_ALLOCA(float, 3 * nchannels);
1354+
float* drds = r + nchannels;
1355+
float* drdt = drds + nchannels;
13531356
for (int i = 0; i < Tex::BatchWidth; ++i, bit <<= 1) {
1354-
float r[4], drds[4], drdt[4]; // temp result
13551357
if (mask & bit) {
13561358
opt.sblur = options.sblur[i];
13571359
opt.tblur = options.tblur[i];
@@ -2102,6 +2104,7 @@ TextureSystemImpl::fade_to_pole(float t, float* accum, float& weight,
21022104
thread_info->tile, options.subimage, miplevel,
21032105
1);
21042106
}
2107+
OIIO_DASSERT(polecolor != nullptr);
21052108
pole = OIIO::clamp(pole, 0.0f, 1.0f);
21062109
pole *= pole; // squaring makes more pleasing appearance
21072110
polecolor += options.firstchannel;

src/oiiotool/printinfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,9 +529,9 @@ OiioTool::print_info(std::ostream& out, Oiiotool& ot, ImageRec* img,
529529
}
530530

531531
for (int s = 0, nsubimages = img->subimages(); s < nsubimages; ++s) {
532-
DASSERT((opt.native ? img->nativespec(s) : img->spec(s)) != nullptr);
533-
print_info_subimage(out, ot, s, nsubimages, img->miplevels(s),
534-
opt.native ? *img->nativespec(s) : *img->spec(s),
532+
const ImageSpec* spec = opt.native ? img->nativespec(s) : img->spec(s);
533+
DASSERT(spec != nullptr);
534+
print_info_subimage(out, ot, s, nsubimages, img->miplevels(s), *spec,
535535
img, nullptr, "", opt, field_re, field_exclude_re,
536536
serformat, verbose);
537537
// If opt.subimages is not set, we print info about first subimage

0 commit comments

Comments
 (0)