Buffer overflow when repeatedly calling Cvb::DeviceFactory::Discover

After about 20 minutes running (even without cameras) buffer overflow happens caused by Discover function. This only happens when running app inside Docker.

Program Output:

...
calling discover504
discover called504
calling discover505
discover called505
calling discover506
discover called506
calling discover507
*** buffer overflow detected ***: /home/app-build/build/discover-test terminated

Dockerfile:

FROM ubuntu:18.04 AS builder

ENV BUILD_FOLDER=build

WORKDIR /home

# Build image
## Essential packages
RUN apt-get update && apt-get upgrade -y && apt-get install -y \
  build-essential \
  cmake \
  git \
  libgtest-dev \
  libice6 \
  libsm6 \
  sudo \
  unzip \
  libfontconfig1 \
  libfreetype6 \
  wget \
  libxext-dev \
  libgtk-3-dev \
  libglade2-0 \
  libglade2-dev \
  libpcap0.8 \
  libcap2 \
  ethtool \
  tar 

 
ARG ARCH=""

ARG CVB_VERSION=13.02.002
RUN mkdir libcvb && cd libcvb
RUN if [ ! -z ${ARCH} ] && [ ${ARCH} = "aarch64"  ]; \
      then wget ftp://ftp.commonvisionblox.com/forum/setups/cvb/linux-aarch64/cvb-${CVB_VERSION}-ubu1804-aarch64.zip; \
      else wget ftp://ftp.commonvisionblox.com/forum/setups/cvb/linux-x86_64/cvb-${CVB_VERSION}-ubu1804-x86_64.zip; \
    fi
RUN unzip -o cvb-${CVB_VERSION}-ubu1804-*.zip && \
  chmod +x ./install_cvb.sh && ./install_cvb.sh && ldconfig

## Discover Test
WORKDIR /home/app-build
COPY . ./
WORKDIR $BUILD_FOLDER
RUN . /etc/profile.d/cvb_environment.sh && cmake .. \
    && make -j4
ENTRYPOINT ["../scripts/run_app.sh", "/home/app-build/build/discover-test"]

start script, run_app.sh:

#!/bin/bash

if [ "$#" -ne 1 ]; then
  echo "Usage: $0 APP_NAME" >&2
  exit 1
fi

CVB_VERSION="13.02.002"
APP_NAME=$1

ln -sf /opt/cvb /opt/cvb-$CVB_VERSION
if [ $? -ne 0 ]; then echo 'Unable to create symbolic link'; exit 1; fi

. /etc/profile.d/cvb_environment.sh
if [ $? -ne 0 ]; then echo 'Unable to load CVB enviroment variables'; exit 1; fi

/etc/init.d/siLogSvc start &> /dev/null
if [ $? -ne 0 ]; then echo 'Unable to start CVB log service'; exit 1; fi

/etc/init.d/siGevSvc start &> /dev/null
if [ $? -ne 0 ]; then echo 'Unable to start CVB GigE daemon service'; exit 1; fi

/etc/init.d/cvmgmtd start &> /dev/null
if [ $? -ne 0 ]; then echo 'Unable to start CVB management daemon service'; exit 1; fi

${APP_NAME}
if [ $? -ne 0 ]; then echo 'Unable to run ${APP_NAME}'; exit 1; fi

exit 0

Test code:

#include <iostream>
#include <cvb/device_factory.hpp>

int main(int argc, char *argv[])
{
  int cnt = 0;
  while(1)
  {
    std::vector<Cvb::Driver::DiscoveryInformation> discover;
    std::cout << "calling discover" << cnt << std::endl;
    discover = Cvb::DeviceFactory::Discover(Cvb::Driver::DiscoverFlags::IncludeInaccessible
                                          | Cvb::Driver::DiscoverFlags::IgnoreVins);
    std::cout << "discover called" << cnt << std::endl;
    cnt++;
  }
}

This sounds very much like a bug we have already fixed with CVB 13.3.4 and later.
Please try updating to at least CVB 13.3.4 and let us know if this fixed the issue.

1 Like

Thanks!. Updated to CVB 13.4.0 and the problem seems fixed.

2 Likes