<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 4.1.1</li>
<li>Operating System / Platform =&gt; Ubuntu 18.04</li>
<li>Compiler =&gt; Python 3.6</li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">Documentation for <code class="notranslate">cv2.randn</code> says  <em>Fills the array with normally distributed random numbers</em>, so I expect it to fill whole array, but it actually works only with the channel 0. Later it says <em>dst - output array of random numbers; the array must be pre-allocated and have 1 to 4 channels</em>, means 3 channel images are allowed and it should fill the whole array. The same for <code class="notranslate">cv2.randu</code>.</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">This code</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="noise = np.zeros((10,10,3), dtype=np.uint8)
print(cv2.randn(noise, 128, 50)[:,:,1:])
print(cv2.randu(noise, 0, 255)[:,:,1:])"><pre class="notranslate"><span class="pl-s1">noise</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">zeros</span>((<span class="pl-c1">10</span>,<span class="pl-c1">10</span>,<span class="pl-c1">3</span>), <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">uint8</span>)
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-en">randn</span>(<span class="pl-s1">noise</span>, <span class="pl-c1">128</span>, <span class="pl-c1">50</span>)[:,:,<span class="pl-c1">1</span>:])
<span class="pl-en">print</span>(<span class="pl-s1">cv2</span>.<span class="pl-en">randu</span>(<span class="pl-s1">noise</span>, <span class="pl-c1">0</span>, <span class="pl-c1">255</span>)[:,:,<span class="pl-c1">1</span>:])</pre></div>
<p dir="auto">prints only zeros.</p>
<p dir="auto">We seem to have found a bug in the JPEG image reading code (which is new in 3.1)<br>
in the EXIF parsing functions.</p>
<p dir="auto">The EXIF parser hangs in reading the JPEG orientation tag, and the<br>
imread() function does not return (explanation see below) and hangs.<br>
Probably the jpeg file was created wrong, but opencv should not hang, this<br>
is the worst possible scenario for us.</p>
<h3 dir="auto">Please state the information for your system</h3>
<ul dir="auto">
<li>OpenCV version:  3.1 / Source file contains the problem</li>
<li>Host OS: Reproduced on Linux (Ubuntu 16.04)  and Windows 10 MSVS 2015</li>
</ul>
<h3 dir="auto">In which part of the OpenCV library you got the issue?</h3>
<p dir="auto">The module affected is imgcodecs, imread() function.</p>
<h3 dir="auto">Expected behaviour</h3>
<p dir="auto">imread() ignores the faulty JPEG tag, or returns an error.</p>
<h3 dir="auto">Actual behaviour</h3>
<p dir="auto">Function imread() hangs indefinitely due to EXIF parsing source code error.</p>
<h3 dir="auto">Additional description</h3>
<p dir="auto">Should read the JPEG tag length, but tries to fseek by -2 bytes which is casted to 0FFFFFFE. The resulting error is not taken care of and the while() loop runs<br>
indefinitely.</p>
<p dir="auto">The file affected is<br>
jpeg_exif.cpp, line 202</p>
<h3 dir="auto">Code example to reproduce the issue / Steps to reproduce the issue</h3>
<p dir="auto">See above.</p>