[jira] [Commented] (POOL-409) BasicDataSource should support GenericObjectPool->getStatsString()

2022-10-04 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-409?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612805#comment-17612805
 ] 

Gary D. Gregory commented on POOL-409:
--

I pushed a snapshot to 
https://repository.apache.org/content/repositories/snapshots/org/apache/commons/commons-pool2/2.12.0-SNAPSHOT/

> BasicDataSource should support GenericObjectPool->getStatsString()
> --
>
> Key: POOL-409
> URL: https://issues.apache.org/jira/browse/POOL-409
> Project: Commons Pool
>  Issue Type: Improvement
>Affects Versions: 2.11.1
>Reporter: Thomas Freller
>Priority: Major
>  Labels: improvement
>   Original Estimate: 2h
>  Remaining Estimate: 2h
>
> Hello,
> I'm developing a Application that is running on a default JRE without an 
> Webserver/JMX.
> For optimizing Database connections it would be very useful if i could access
>  
> BasicDataSource->GenericObjectPool->{*}getStatsString(){*}
>  
> I don't see any reason why this Method is protected and not public in 
> GenericObjectPool.
> Then BasicDataSource shoud provide a method getStatsString() or the values 
> that represent the statistic data.
>  
> If there is any other easy way to access this data within my Java Code I'll 
> implement this if you could give me an example how to get this working 
> easily. I don't want do configure any jmx stuff.
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (POOL-407) Threads get stuck when idleObjects list is empty.

2022-10-04 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/POOL-407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612791#comment-17612791
 ] 

Gary D. Gregory commented on POOL-407:
--

[~dmfs] 

Please provide your test as a GitHub PR as it currently does not look like it 
would even compile since there is no Foo or FooPool types in your example 
folder. We need a failing test to debug ;)

> Threads get stuck when idleObjects list is empty.
> -
>
> Key: POOL-407
> URL: https://issues.apache.org/jira/browse/POOL-407
> Project: Commons Pool
>  Issue Type: Bug
>Affects Versions: 2.8.1
>Reporter: Sarthak Shukla
>Priority: Major
>
> While borrowing object from pool, threads are getting stuck. I initialised 
> the pool size as 1. And had 3 threads created. First thread enters 
> borrowObject method, since there are no idle objects to poll from, it will 
> create one object and move forward.
> {code:java}
> p = (PooledObject)this.idleObjects.pollFirst();
> if (p == null) {
>   p = this.create();
>   if (p != null) {
>  create = true;
>   }
> } {code}
> The other two threads will also follow same path and check for idle 
> objects(there are none), will try to create one object but the pool size is 
> set to 1. Thus, the two threads will move forward and enter 
> *idleObjects.takeFirst()* function. Value of blockWhenExhausted is true and 
> borrowMaxWaitMillis is -1 as we don't want timeout.
> {code:java}
> if (blockWhenExhausted) {
>if (p == null) {
>   if (borrowMaxWaitMillis < 0L) {
>p = (PooledObject)this.idleObjects.takeFirst();
>   } else {
>p = (PooledObject)this.idleObjects.pollFirst(borrowMaxWaitMillis, 
> TimeUnit.MILLISECONDS);
>   }
>}
>if (p == null) {
>   throw new NoSuchElementException("Timeout waiting for idle object");
>}
> }{code}
> Now, the main thread does *this.factory.activateObject(p);* and object gets 
> activated. Now, when the validation is checked *validate = 
> this.factory.validateObject(p);* it comes out to be false as provider might 
> have been disconnected.
> So, the object is destroyed by calling *this.destroy(p);*
> {code:java}
> private void destroy(PooledObject toDestroy) throws Exception {
>  toDestroy.invalidate();
>  this.idleObjects.remove(toDestroy);
>  this.allObjects.remove(new 
> BaseGenericObjectPool.IdentityWrapper(toDestroy.getObject()));
>  try {
> this.factory.destroyObject(toDestroy);
>  } finally {
> this.destroyedCount.incrementAndGet();
> this.createCount.decrementAndGet();
>  }
> }{code}
> The object which was created is now destroyed and removed from idleObject and 
> allObjects list. Now, the other two threads are still waiting to take object 
> from idle objects list but there are no object present. Hence, the two 
> threads are in wait state for infinite period and the application waits 
> forever until we kill the process.
> {code:java}
> public E takeFirst() throws InterruptedException {
>this.lock.lock();
>Object var2;
>try {
>   Object x;
>   while((x = this.unlinkFirst()) == null) {
>  this.notEmpty.await();
>   }
>   var2 = x;
> } finally {
>   this.lock.unlock();
> }
> return var2;
> } {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (VALIDATOR-486) the IBAN validator does not support all the IBAN supported countries

2022-10-04 Thread Gary D. Gregory (Jira)


[ 
https://issues.apache.org/jira/browse/VALIDATOR-486?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612787#comment-17612787
 ] 

Gary D. Gregory commented on VALIDATOR-486:
---

Hi [~nicola.gioia] 

Thank you for your report :)

Feel free to provide a PR on GitHub.

> the IBAN validator does not support all the IBAN supported countries
> 
>
> Key: VALIDATOR-486
> URL: https://issues.apache.org/jira/browse/VALIDATOR-486
> Project: Commons Validator
>  Issue Type: Bug
>Affects Versions: 1.7
>Reporter: Nicola Gioia
>Priority: Major
>
> the list of supported countries for iban miss the following countries:
> |Burundi|BI|
> |Djibouti|DJ|
> |Libya|LY|
> |Russia|RU|
> |Sudan|SD|



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (DAEMON-449) Prunsrv fails to stop Open Liberty Windows service

2022-10-04 Thread Mark Thomas (Jira)


[ 
https://issues.apache.org/jira/browse/DAEMON-449?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612763#comment-17612763
 ] 

Mark Thomas commented on DAEMON-449:


You could try updating to the latest version but I doubt that will help.

Enabling debug logging, particularly with the latest version, might provide 
some additional information.

If you can show that Daemon isn't calling stop then there would be a bug here 
but the logs indicate that stop is being called and Open Liberty isn't 
responding.

I suspect the issues is in Open Liberty rather than Commons Daemon. The 
different exit code (20 vs 0) might be a clue.

> Prunsrv fails to stop Open Liberty Windows service
> --
>
> Key: DAEMON-449
> URL: https://issues.apache.org/jira/browse/DAEMON-449
> Project: Commons Daemon
>  Issue Type: Bug
>  Components: prunsrv
>Affects Versions: 1.2.2
> Environment: I don't think the Windows version matters, but I am 
> using:
> Microsoft Windows [Version 10.0.19044.2006]
>Reporter: Jim Blye
>Priority: Major
> Attachments: commons-daemon.2022-09-28.log, 
> commons-daemon.2022-09-28_afterKillingServer.log, server.bat
>
>
> When Prunsrv is used to register Open Liberty 
> ([https://openliberty.io|https://openliberty.io/]) as a Windows Service, 
> stopping the service hangs randomly.
> *To recreate the problem:*
>   1) Download open liberty  ~300MB
>            
> [https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/22.0.0.10/openliberty-22.0.0.10.zip]
>   Alternatively, you could use just the liberty kernel ~10MB
>           
> [https://public.dhe.ibm.com/ibmdl/export/pub/software/openliberty/runtime/release/22.0.0.10/openliberty-kernel-22.0.0.10.zip]
>   2) md C:\temp\openliberty
>    unzip openliberty-22.0.0.10.zip into C:\temp\openliberty
>   3) cd C:\temp\openliberty\wlp\bin
>   4) Run these two commands to make sure the server runs and to initialize 
> the environment:
>    server start
>    server stop
>    5) Register liberty as a service (parameter is case sensitive).  The 
> following command is used to invoke prunsrv to register the service using the 
> default name of defaultServer
>     server registerWinService
>     6)  Open the windows "services" app (services.msc).   Start and stop the 
> service until the stop hangs.  It usually doesn't take more than a couple of 
> tries.
>  
> *Details*
> The *server.bat* script registers the service like this:
> "C:\temp\openliberty\wlp\bin\tools\win\prunsrv.exe"  //IS//defaultServer 
> --Startup=manual --DisplayName="defaultServer" --Description="Open Liberty" 
> ++DependsOn=Tcpip 
> --LogPath="C:\temp\openliberty\wlp\usr\servers\defaultServer\logs" 
> --StdOutput=auto --StdError=auto --StartMode=exe 
> --StartPath="C:\temp\openliberty\wlp" 
> --StartImage="C:\temp\openliberty\wlp\bin\server.bat" 
> ++StartParams=start#defaultServer --StopMode=exe 
> --StopPath="C:\temp\openliberty\wlp" --StopImage="C:\temp\wlp\bin\server.bat" 
> ++StopParams=stop#defaultServer --ServiceUser=LocalSystem
> After registering the service you can look at its properties.  You will see:
>    Path to executable:
>    C:\temp\openliberty\wlp\bin\tools\win\prunsrv.exe //RS//defaultServer
> When I (and many of our customers) try to stop the service, it hangs.   At 
> that point, the server, named defaultServer is still up and running.  I can 
> send commands to the server.  For instance, I can execute a "server dump" 
> command. This sends the "dump" command to the server, and the server writes 
> information to a file.  I can also stop the server by executing "server 
> stop".  This sends the "stop" command to the server which causes the server 
> to stop.  When the server stops, the hanging Windows service stops as well.
> I have attached a *server.bat* which adds --LogLevel Debug to the prunsrv 
> commands and also *commons-daemon.2022-09-28.log* which demonstrates the 
> problem. It shows registering, starting, and stopping the service.  Finally, 
> I uploaded {*}commons-daemon.2022-09-28_afterKillingServer.log{*}, which is a 
> continuation of the other log file which shows the result of issuing the 
> server stop command to stop the server.
> Thanks for looking at this.
> Jim Blye



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Resolved] (DAEMON-448) Service start fails with default Eclipse Temurin install

2022-10-04 Thread Mark Thomas (Jira)


 [ 
https://issues.apache.org/jira/browse/DAEMON-448?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mark Thomas resolved DAEMON-448.

Fix Version/s: 1.3.2
   Resolution: Fixed

Fixed. It was a NULL pointer de-reference when no JVM was configured.

> Service start fails with default Eclipse Temurin install
> 
>
> Key: DAEMON-448
> URL: https://issues.apache.org/jira/browse/DAEMON-448
> Project: Commons Daemon
>  Issue Type: Bug
>  Components: prunsrv
>Affects Versions: 1.3.1
> Environment: * Windows 10 Pro 21H2 (OS Build 19044.1889) 64 bit
>  * Eclipse Temurin Windows x64 JRE 11 (jdk-11.0.16.1+1) x64
>  ** Screenshot from website, no direct link possible:
>  ** !image-2022-09-16-14-53-28-807.png!
>Reporter: Glenn Matthys
>Priority: Major
> Fix For: 1.3.2
>
> Attachments: image-2022-09-16-14-49-32-981.png, 
> image-2022-09-16-14-53-28-807.png, image-2022-09-16-15-02-53-131.png
>
>
> When installing Eclipse Temurin JRE version 11, notice _Set JAVA_HOME 
> variable_ and _JavaSoft (Oracle) registry keys_ options are disabled in the 
> default setup:
> !image-2022-09-16-14-49-32-981.png!
> prunsrv.exe successfully installs the service, but when trying to start it 
> prunsrv.exe crashes:
> {{Faulting application name: xxx.exe, version: 1.3.1.0, time stamp: 
> 0x6271349d}}
> {{Faulting module name: xxx.exe, version: 1.3.1.0, time stamp: 0x6271349d}}
> {{Exception code: 0xc005}}
> {{Fault offset: 0x7130}}
> {{Faulting process id: 0x1ddc}}
> {{Faulting application start time: 0x01d8c9ca012bfb46}}
> {{Faulting application path: C:\Program Files\xxx\xxx.exe}}
> {{Faulting module path: C:\Program Files\xxx\xxx.exe}}
> {{Report Id: a35b4a6a-63a3-4426-8061-495550439a97}}
> {{Faulting package full name: }}
> {{Faulting package-relative application ID: }}
> However when the default options are overridden and _Set JAVA_HOME variable_ 
> and _JavaSoft (Oracle) registry keys_ options are enabled:
> !image-2022-09-16-15-02-53-131.png!
> prunsrv.exe works correctly.
> Having prunsrv.exe work correctly or at least not die with an 0xc005 
> (Access Denied) exception would improve user experience.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (DAEMON-448) Service start fails with default Eclipse Temurin install

2022-10-04 Thread Mark Thomas (Jira)


[ 
https://issues.apache.org/jira/browse/DAEMON-448?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612688#comment-17612688
 ] 

Mark Thomas commented on DAEMON-448:


If JAVA_HOME isn't defined and there is no Java defined in the expected 
registry locations then you are going to have to explicitly define the JVM you 
want the service to use.

What we should be able to do is handle the situation better and fail to start 
with a useful error message rather than crashing.

> Service start fails with default Eclipse Temurin install
> 
>
> Key: DAEMON-448
> URL: https://issues.apache.org/jira/browse/DAEMON-448
> Project: Commons Daemon
>  Issue Type: Bug
>  Components: prunsrv
>Affects Versions: 1.3.1
> Environment: * Windows 10 Pro 21H2 (OS Build 19044.1889) 64 bit
>  * Eclipse Temurin Windows x64 JRE 11 (jdk-11.0.16.1+1) x64
>  ** Screenshot from website, no direct link possible:
>  ** !image-2022-09-16-14-53-28-807.png!
>Reporter: Glenn Matthys
>Priority: Major
> Attachments: image-2022-09-16-14-49-32-981.png, 
> image-2022-09-16-14-53-28-807.png, image-2022-09-16-15-02-53-131.png
>
>
> When installing Eclipse Temurin JRE version 11, notice _Set JAVA_HOME 
> variable_ and _JavaSoft (Oracle) registry keys_ options are disabled in the 
> default setup:
> !image-2022-09-16-14-49-32-981.png!
> prunsrv.exe successfully installs the service, but when trying to start it 
> prunsrv.exe crashes:
> {{Faulting application name: xxx.exe, version: 1.3.1.0, time stamp: 
> 0x6271349d}}
> {{Faulting module name: xxx.exe, version: 1.3.1.0, time stamp: 0x6271349d}}
> {{Exception code: 0xc005}}
> {{Fault offset: 0x7130}}
> {{Faulting process id: 0x1ddc}}
> {{Faulting application start time: 0x01d8c9ca012bfb46}}
> {{Faulting application path: C:\Program Files\xxx\xxx.exe}}
> {{Faulting module path: C:\Program Files\xxx\xxx.exe}}
> {{Report Id: a35b4a6a-63a3-4426-8061-495550439a97}}
> {{Faulting package full name: }}
> {{Faulting package-relative application ID: }}
> However when the default options are overridden and _Set JAVA_HOME variable_ 
> and _JavaSoft (Oracle) registry keys_ options are enabled:
> !image-2022-09-16-15-02-53-131.png!
> prunsrv.exe works correctly.
> Having prunsrv.exe work correctly or at least not die with an 0xc005 
> (Access Denied) exception would improve user experience.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Resolved] (DAEMON-446) Update service (//US) does not change DependsOn

2022-10-04 Thread Mark Thomas (Jira)


 [ 
https://issues.apache.org/jira/browse/DAEMON-446?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mark Thomas resolved DAEMON-446.

Fix Version/s: 1.3.2
   Resolution: Fixed

Thanks for the report. That looks like an oversight to me. Now fixed.

> Update service (//US) does not change DependsOn
> ---
>
> Key: DAEMON-446
> URL: https://issues.apache.org/jira/browse/DAEMON-446
> Project: Commons Daemon
>  Issue Type: Bug
>  Components: Procrun
>Affects Versions: 1.2.2
> Environment: Windows 10, Windows Server several versions
>Reporter: Pavel Rund
>Priority: Major
> Fix For: 1.3.2
>
>
> When installing a service, I can set dependency on other services using the 
> --DependsOn parameter. But when a try to add this dependency using //US 
> directive, nothing happens.
> I know we don't use the latest version of procrun but I checked source codes 
> and if I don't misread it, the //US directive still does not chage DependsOn 
> parameter of the service.
> Is that a purspose? If not, can this be repaired?



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Resolved] (COMPRESS-627) Pack200 causes a 'archive.3E' error if it’s not in the system class loader.

2022-10-04 Thread Gary D. Gregory (Jira)


 [ 
https://issues.apache.org/jira/browse/COMPRESS-627?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory resolved COMPRESS-627.
--
Fix Version/s: 1.22
   Resolution: Fixed

[~anatawa12] 

Thank you for your report.

The classes in that case are now loaded from the Pack200 class loader.

Please try git master or a snapshot build from 
[https://repository.apache.org/content/repositories/snapshots/]

 

> Pack200 causes a 'archive.3E' error if it’s not in the system class loader.
> ---
>
> Key: COMPRESS-627
> URL: https://issues.apache.org/jira/browse/COMPRESS-627
> Project: Commons Compress
>  Issue Type: Bug
>Affects Versions: 1.21
> Environment: {code:java}
> anatawa12@anatawa12-book:~/commons-compress-pack200-test $ neofetch --off 
> --stdout
> anataw...@owlan031072216.sras.sic.shibaura-it.ac.jp
> ---
> OS: macOS 12.6 21G115 arm64
> Host: MacBookPro18,4
> Kernel: 21.6.0
> Uptime: 11 days, 8 hours, 58 mins
> Packages: 199 (brew)
> Shell: zsh 5.8.1
> Resolution: 1800x1169
> DE: Aqua
> WM: Quartz Compositor
> WM Theme: Blue (Light)
> Terminal: iTerm2
> Terminal Font: Monaco 12
> CPU: Apple M1 Max
> GPU: Apple M1 Max
> Memory: 10849MiB / 65536MiB
> anatawa12@anatawa12-book:~/commons-compress-pack200-test $ java -version
> openjdk version "1.8.0_332"
> OpenJDK Runtime Environment (Zulu 8.62.0.19-CA-macos-aarch64) (build 
> 1.8.0_332-b09)
> OpenJDK 64-Bit Server VM (Zulu 8.62.0.19-CA-macos-aarch64) (build 25.332-b09, 
> mixed mode)
> {code}
>Reporter: anatawa12
>Priority: Major
> Fix For: 1.22
>
> Attachments: Main-1.java
>
>
> {code:java}
> import org.apache.commons.compress.java.util.jar.Pack200;
> import java.lang.reflect.Method;
> import java.net.URLClassLoader;
> import java.net.URL;
> import java.io.File;
> class Main {
>   public static void main(String[] args) throws Throwable {
> URLClassLoader ucl = new URLClassLoader(new URL[] {
>   new File(".").toURI().toURL(),
>   new File("commons-compress-1.21.jar").toURI().toURL(),
> }, null);
> System.out.println("=== Unpacker ===");
> Method method;
> try {
>   method = 
> ucl.loadClass("InClassLoaderClass").getDeclaredMethod("unpacker");
>   method.setAccessible(true);
>   method.invoke(null);
> } catch (Throwable t) {
>   t.printStackTrace();
> }
> System.out.println("=== Packer ===");
> try {
>   method = 
> ucl.loadClass("InClassLoaderClass").getDeclaredMethod("packer");
>   method.setAccessible(true);
>   method.invoke(null);
> } catch (Throwable t) {
>   t.printStackTrace();
> }
>   }
> }
> class InClassLoaderClass {
>   public static void unpacker() {
> Pack200.newUnpacker();
>   }
>   public static void packer() {
> Pack200.newPacker();
>   }
> }
> {code}
> execute this code (same as attached {{Main.java}}) with 
> {{ClassLoaderClass.class}} (compiled code of this file) and 
> {{commons-compress-1.21.jar}} is on working directory will cause the 
> following error:
> {code:java}
> anatawa12@anatawa12-book:~/commons-compress-pack200-test $ javac -cp 
> commons-compress-1.21.jar Main.java && java Main
> === Unpacker ===
> java.lang.reflect.InvocationTargetException
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)
>   at Main.main(Main.java:19)
> Caused by: java.lang.Error: archive.3E
>   at 
> org.apache.commons.compress.java.util.jar.Pack200$2.run(Pack200.java:100)
>   at java.security.AccessController.doPrivileged(Native Method)
>   at 
> org.apache.commons.compress.java.util.jar.Pack200.newUnpacker(Pack200.java:91)
>   at InClassLoaderClass.unpacker(Main.java:37)
>   ... 5 more
> Caused by: java.lang.ClassNotFoundException: 
> org.apache.commons.compress.harmony.unpack200.Pack200UnpackerAdapter
>   at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
>   at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
>   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
>   at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
>   at 
> org.apache.commons.compress.java.util.jar.Pack200$2.run(Pack200.java:98)
>   ... 8 more
> === Packer ===
> java.lang.reflect.InvocationTargetException
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> 

[jira] [Updated] (COMPRESS-627) Pack200 causes a 'archive.3E' error if it’s not in the system class loader.

2022-10-04 Thread Gary D. Gregory (Jira)


 [ 
https://issues.apache.org/jira/browse/COMPRESS-627?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory updated COMPRESS-627:
-
Summary: Pack200 causes a 'archive.3E' error if it’s not in the system 
class loader.  (was: Pack200 by apache compress cause archive.3E error if it’s 
not on system ClassLoader.)

> Pack200 causes a 'archive.3E' error if it’s not in the system class loader.
> ---
>
> Key: COMPRESS-627
> URL: https://issues.apache.org/jira/browse/COMPRESS-627
> Project: Commons Compress
>  Issue Type: Bug
>Affects Versions: 1.21
> Environment: {code:java}
> anatawa12@anatawa12-book:~/commons-compress-pack200-test $ neofetch --off 
> --stdout
> anataw...@owlan031072216.sras.sic.shibaura-it.ac.jp
> ---
> OS: macOS 12.6 21G115 arm64
> Host: MacBookPro18,4
> Kernel: 21.6.0
> Uptime: 11 days, 8 hours, 58 mins
> Packages: 199 (brew)
> Shell: zsh 5.8.1
> Resolution: 1800x1169
> DE: Aqua
> WM: Quartz Compositor
> WM Theme: Blue (Light)
> Terminal: iTerm2
> Terminal Font: Monaco 12
> CPU: Apple M1 Max
> GPU: Apple M1 Max
> Memory: 10849MiB / 65536MiB
> anatawa12@anatawa12-book:~/commons-compress-pack200-test $ java -version
> openjdk version "1.8.0_332"
> OpenJDK Runtime Environment (Zulu 8.62.0.19-CA-macos-aarch64) (build 
> 1.8.0_332-b09)
> OpenJDK 64-Bit Server VM (Zulu 8.62.0.19-CA-macos-aarch64) (build 25.332-b09, 
> mixed mode)
> {code}
>Reporter: anatawa12
>Priority: Major
> Attachments: Main-1.java
>
>
> {code:java}
> import org.apache.commons.compress.java.util.jar.Pack200;
> import java.lang.reflect.Method;
> import java.net.URLClassLoader;
> import java.net.URL;
> import java.io.File;
> class Main {
>   public static void main(String[] args) throws Throwable {
> URLClassLoader ucl = new URLClassLoader(new URL[] {
>   new File(".").toURI().toURL(),
>   new File("commons-compress-1.21.jar").toURI().toURL(),
> }, null);
> System.out.println("=== Unpacker ===");
> Method method;
> try {
>   method = 
> ucl.loadClass("InClassLoaderClass").getDeclaredMethod("unpacker");
>   method.setAccessible(true);
>   method.invoke(null);
> } catch (Throwable t) {
>   t.printStackTrace();
> }
> System.out.println("=== Packer ===");
> try {
>   method = 
> ucl.loadClass("InClassLoaderClass").getDeclaredMethod("packer");
>   method.setAccessible(true);
>   method.invoke(null);
> } catch (Throwable t) {
>   t.printStackTrace();
> }
>   }
> }
> class InClassLoaderClass {
>   public static void unpacker() {
> Pack200.newUnpacker();
>   }
>   public static void packer() {
> Pack200.newPacker();
>   }
> }
> {code}
> execute this code (same as attached {{Main.java}}) with 
> {{ClassLoaderClass.class}} (compiled code of this file) and 
> {{commons-compress-1.21.jar}} is on working directory will cause the 
> following error:
> {code:java}
> anatawa12@anatawa12-book:~/commons-compress-pack200-test $ javac -cp 
> commons-compress-1.21.jar Main.java && java Main
> === Unpacker ===
> java.lang.reflect.InvocationTargetException
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)
>   at Main.main(Main.java:19)
> Caused by: java.lang.Error: archive.3E
>   at 
> org.apache.commons.compress.java.util.jar.Pack200$2.run(Pack200.java:100)
>   at java.security.AccessController.doPrivileged(Native Method)
>   at 
> org.apache.commons.compress.java.util.jar.Pack200.newUnpacker(Pack200.java:91)
>   at InClassLoaderClass.unpacker(Main.java:37)
>   ... 5 more
> Caused by: java.lang.ClassNotFoundException: 
> org.apache.commons.compress.harmony.unpack200.Pack200UnpackerAdapter
>   at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
>   at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
>   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
>   at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
>   at 
> org.apache.commons.compress.java.util.jar.Pack200$2.run(Pack200.java:98)
>   ... 8 more
> === Packer ===
> java.lang.reflect.InvocationTargetException
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>   at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:498)
>   at Main.main(Main.java:28)
> 

[jira] [Commented] (DAEMON-445) Changes of DAEMON-441 cause trouble with empty env vars

2022-10-04 Thread Mark Thomas (Jira)


[ 
https://issues.apache.org/jira/browse/DAEMON-445?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612610#comment-17612610
 ] 

Mark Thomas commented on DAEMON-445:


How are you setting an empty environment variable in Windows. Generally, trying 
to do that deletes the environment variable.

> Changes of DAEMON-441 cause trouble with empty env vars
> ---
>
> Key: DAEMON-445
> URL: https://issues.apache.org/jira/browse/DAEMON-445
> Project: Commons Daemon
>  Issue Type: Bug
>Affects Versions: 1.3.1
>Reporter: Alexander Fischer
>Priority: Major
>
> The changes done via DAEMON-441, namely 
> [https://github.com/apache/commons-daemon/commit/97b31058ecf5e4dc202188d8e8917f6caa90dcfc#diff-e7f9bbe0d9947378640c1e1c91d8dc72c93e6d1034218458158a1cc43f2f3b9fR278]
>  lead to a failing service installation in case the environment variable 
> exists but has no value. 
> In my use case the supported environment variables are explicitly set empty 
> if defaults shall be used. This is done to avoid interference with 
> environment variables which may be set by the caling process. 
> In such a case example output is:
> {noformat}
> [2022-06-29 11:32:11] [error] [10552] Error getting environment variable 
> PR_LibraryPath
> [2022-06-29 11:32:11] [warn]  [10552] Failed to grant service user '.\user' 
> write permissions to log path 'C:\Windows\system32\LogFiles\Apache' due to 
> error '19: The media is write protected.'
> {noformat}
> while the environment is set
> {noformat}
> PR_DESCRIPTION: tomcat-service description
> PR_DISPLAYNAME: tomcat-service
> PR_INSTALL: C:\apache-tomcat\bin\tomcat9.exe
> PR_SERVICEUSER: .\hidden
> PR_SERVICEPASSWORD: hidden
> PR_STARTUP: auto
> PR_CLASSPATH: 
> C:\apache-tomcat/bin/bootstrap.jar;C:\apache-tomcat/bin/tomcat-juli.jar;
> PR_JAVA_HOME: C:\jdk
> PR_JVM: C:\jdk\bin\server\jvm.dll
> PR_JVMMS: 256
> PR_JVMMX: 3072
> PR_JVMOPTIONS: 
> -Dcatalina.base=C:\tomcat-service;-Dcatalina.home=C:\apache-tomcat;-Djava.io.tmpdir=C:\tomcat-service/temp;
> PR_ENVIRONMENT: 
> PATH='C:\Windows;C:\Windows\System32;C:\Windows\System32\Wbem;C:\apache-tomcat\bin'
> PR_LIBRARYPATH: C:\apache-tomcat/bin
> PR_STARTCLASS: org.apache.catalina.startup.Bootstrap
> PR_STARTMETHOD: 
> PR_STARTPARAMS: start
> PR_STARTMODE: jvm
> PR_STARTPATH: C:\tomcat-service
> PR_STOPCLASS: org.apache.catalina.startup.Bootstrap
> PR_STOPMETHOD: 
> PR_STOPPARAMS: stop
> PR_STOPMODE: jvm
> PR_STOPPATH: C:\tomcat-service
> PR_STOPTIMEOUT: 60
> PR_LOGJNIMESSAGES: 0
> PR_LOGLEVEL: Info
> PR_LOGPATH: C:\Logs\tomcat-service
> PR_LOGPREFIX: tomcat-service
> PR_STDERROR: auto
> PR_STDOUTPUT: auto
> PR_DEPENDSON: postgresql-x64-11;
> {noformat}
> Means, the environment variables PR_STOPMETHOD, PR_LIBRARYPATH and 
> PR_STARTMETHOD are defined but empty.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Closed] (DAEMON-435) While stopping service, service crashed with error 1067

2022-10-04 Thread Mark Thomas (Jira)


 [ 
https://issues.apache.org/jira/browse/DAEMON-435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mark Thomas closed DAEMON-435.
--
Resolution: Cannot Reproduce

No further information provided by OP.

> While stopping service, service crashed with error 1067
> ---
>
> Key: DAEMON-435
> URL: https://issues.apache.org/jira/browse/DAEMON-435
> Project: Commons Daemon
>  Issue Type: Bug
>Affects Versions: 1.2.4
>Reporter: Kaviarasi
>Priority: Blocker
>
> When stopping the service, service crashes with Error 1067: The process 
> terminated unexpectedly.
>  
> When enabled the debug mode for prunsrv, following messages are seen
>  
> [2021-10-29 12:34:53] [debug] ( prunsrv.c:1892) [ 1816] Apache Commons Daemon 
> procrun log initialized.
> [2021-10-29 12:34:53] [info]  ( prunsrv.c:1896) [ 1816] Apache Commons Daemon 
> procrun (1.2.4.0 64-bit) started.
> [2021-10-29 12:34:53] [info]  ( prunsrv.c:945 ) [ 1816] Updating service...
> [2021-10-29 12:34:53] [warn]  ( service.c:143 ) [ 1816] Failed to obtain 
> service description
> [2021-10-29 12:34:53] [info]  ( prunsrv.c:1007) [ 1816] Updated service 
> 'OracleAVAgent'.
> [2021-10-29 12:34:53] [info]  ( prunsrv.c:1014) [ 1816] Finished updating 
> service 'OracleAVAgent'.
> [2021-10-29 12:34:53] [info]  ( prunsrv.c:1980) [ 1816] Apache Commons Daemon 
> procrun finished.
> [2021-10-29 12:34:53] [debug] ( prunsrv.c:1032) [12208] reportServiceStatusE: 
> dwCurrentState = 4, dwWin32ExitCode = 0, dwWaitHint = 0, 
> dwServiceSpecificExitCode = 0.
> [2021-10-29 12:34:53] [debug] ( prunsrv.c:1032) [12208] reportServiceStatusE: 
> dwCurrentState = 3, dwWin32ExitCode = 0, dwWaitHint = 3000, 
> dwServiceSpecificExitCode = 0.
> [2021-10-29 12:34:53] [info]  ( prunsrv.c:1132) [10076] Stopping service...
> [2021-10-29 12:34:53] [debug] ( javajni.c:414 ) [10076] Loaded JVM DLL '', 
> home ''.
> [2021-10-29 12:34:53] [debug] ( javajni.c:419 ) [10076] 
> JNI_GetCreatedJavaVMs...
> [2021-10-29 12:34:53] [debug] ( javajni.c:1039) [ 8808] DLL search path set 
> to '
> [2021-10-29 12:34:53] [debug] ( javajni.c:1003) [ 8808] argv[0] = STOP
> [2021-10-29 12:34:53] [debug] ( javajni.c:1003) [ 8808] argv[1] = -l
> [2021-10-29 12:34:53] [debug] ( javajni.c:1003) [ 8808] argv[2] = WARNING
> [2021-10-29 12:34:53] [debug] ( javajni.c:1062) [ 8808] Java worker thread 
> started for oracle/av/platform/agent/AgentController:main
> [2021-10-29 12:34:53] [debug] ( javajni.c:1068) [ 8808] JNI calling static 
> void method oracle/av/platform/agent/AgentController:main
> [2021-10-29 12:34:54] [debug] ( javajni.c:566 ) [12220] Exit hook with exit 
> code 0



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (DAEMON-447) Allow to rotate stdout and stderr redirected logs

2022-10-04 Thread Mark Thomas (Jira)


[ 
https://issues.apache.org/jira/browse/DAEMON-447?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612594#comment-17612594
 ] 

Mark Thomas commented on DAEMON-447:


Please provide your proposed change as a patch attached to this issue or as a 
PR via GitHub.

> Allow to rotate stdout and stderr redirected logs 
> --
>
> Key: DAEMON-447
> URL: https://issues.apache.org/jira/browse/DAEMON-447
> Project: Commons Daemon
>  Issue Type: Improvement
>  Components: prunsrv
>Affects Versions: 1.3.0, 1.3.1
> Environment: Windows 10; WIndows Server  2016
>Reporter: Ivan Pedruzzi
>Priority: Major
>
> We have a large legacy web application which makes use of System.out.println 
> to print errors.  
> Our Tomcat 9 is configured to redirect stdout to file using switch --StdOut
> In some peculiar conditions our web application can print a very large amount 
> error which end up in the log file and can quickly fill the hard drive, 
> crashing the system.  
> Looking at the code in prunsrv.c  it is possible to implement a simple 
> rotation policy which would limit the size of the log from stdout to a 
> configurable number of bytes.
> Piggy backing on the worker thread "eventThread", when the log file size is 
> above a configurable threshold (new option  StdOutFileMaxSize) we could make 
> a copy of the log and truncate the file.   
> To enable the rotation for the redirects, we would need 2 options:
> --Rotate 
> --StdOutFileMaxSize   
> These could be used for both stderr and stdout or split in dedicated options
>  
> Here is the worked altered with my change. In my local tests it behaves as I 
> expect.  
> DWORD WINAPI eventThread(LPVOID lpParam)
> {
>     DWORD dwRotateCnt = SO_LOGROTATE;
>     for (;;) {
>         DWORD dw = WaitForSingleObject(gSignalEvent, 1000);
>         if (dw == WAIT_TIMEOUT) {
>             /* Do process maintenance */
>             if (SO_LOGROTATE != 0 && --dwRotateCnt == 0) {
>                 /* Perform log rotation. */
>                
>               /* START CHANGE */ 
>         
>                 __int64 MAX_Mbytes = SO_STDOUTFILEMAXSIZE;
>                 struct _stat64 fileInfo;
>                 if (gStdwrap.szStdOutFilename 
>                     && gStdwrap.fpStdOutFile
>                     && _fstat64(_fileno(gStdwrap.fpStdOutFile), ) == > 0
>                     && fileInfo.st_size > MAX_Mbytes) {
>                     WCHAR sPath[SIZ_PATHLEN];
>                     lstrlcpyW(sPath, MAX_PATH, gStdwrap.szStdOutFilename);
>                     lstrlcatW(sPath, SIZ_PATHMAX, L"-backup.log");
>                     //Make a copy of current log before truncating it
>                     CopyFileW(gStdwrap.szStdOutFilename, sPath, FALSE);
>                     //close current handle 
>                     fclose(gStdwrap.fpStdOutFile);
>                     //re-open file to truncate it
>                     FILE* tempHandle = _wfsopen(gStdwrap.szStdOutFilename, 
> L"w", _SH_DENYNO);
>                     fclose(tempHandle);
>                     
>                     //re-open in append mode
>                     gStdwrap.fpStdOutFile = 
> _wfsopen(gStdwrap.szStdOutFilename, L"a", _SH_DENYNO);
>                     _dup2(_fileno(gStdwrap.fpStdOutFile), 1);
>                     *stdout = *(gStdwrap.fpStdOutFile);
>                  }
>                  /* END CHANGE */ 
>                  dwRotateCnt = SO_LOGROTATE;
>             }
>             continue;
>         }
>         if (dw == WAIT_OBJECT_0 && gSignalValid) {
>             if (!GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT, 0)) {
>                 /* Invoke Thread dump */
>                 if (gWorker && _jni_startup)
>                     apxJavaDumpAllStacks(gWorker);
>             }
>             ResetEvent(gSignalEvent);
>             continue;
>         }
>         break;
>     }
>     ExitThread(0);
>     return 0;
>     UNREFERENCED_PARAMETER(lpParam);
> }
>    
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Created] (VALIDATOR-486) the IBAN validator does not support all the IBAN supported countries

2022-10-04 Thread Nicola Gioia (Jira)
Nicola Gioia created VALIDATOR-486:
--

 Summary: the IBAN validator does not support all the IBAN 
supported countries
 Key: VALIDATOR-486
 URL: https://issues.apache.org/jira/browse/VALIDATOR-486
 Project: Commons Validator
  Issue Type: Bug
Affects Versions: 1.7
Reporter: Nicola Gioia


the list of supported countries for iban miss the following countries:
|Burundi|BI|
|Djibouti|DJ|
|Libya|LY|
|Russia|RU|
|Sudan|SD|



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Closed] (COMPRESS-628) OutOfMemoryError on pack200 NewAttributeBands.readNextUnionCase

2022-10-04 Thread Andrii Hudz (Jira)


 [ 
https://issues.apache.org/jira/browse/COMPRESS-628?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andrii Hudz closed COMPRESS-628.


Fixed

> OutOfMemoryError on pack200 NewAttributeBands.readNextUnionCase
> ---
>
> Key: COMPRESS-628
> URL: https://issues.apache.org/jira/browse/COMPRESS-628
> Project: Commons Compress
>  Issue Type: Bug
>  Components: Archivers
>Affects Versions: 1.21
> Environment: ubuntu18, java-11-openjdk-amd64
>Reporter: Andrii Hudz
>Priority: Major
> Fix For: 1.22
>
>
> Similar to https://issues.apache.org/jira/browse/COMPRESS-626
> pack200.NewAttributeBands.readNextUnionCase can result in an infinite loop 
> that finally leads to an out of memory error.
> {code:java}
> import org.apache.commons.compress.harmony.pack200.*;
> public class ApacheCompress_1_22_90a4d8b3_OutOfMemory {
> public static void main(String[] args) throws Exception {
> CPUTF8 name = new CPUTF8("");
> CPUTF8 layout = new CPUTF8("Re\\T");
> new NewAttributeBands(1, null, null,
> new AttributeDefinitionBands.AttributeDefinition(35, 
> AttributeDefinitionBands.CONTEXT_CLASS, name, layout)
> );
> }
> }
>  {code}
>  
> exception on 1.22 snapshot commit(90a4d8b3)
> {code:java}
> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space: 
> failed reallocation of scalar replaced objects {code}
> exception on  1.21
> {code:java}
> java.lang.OutOfMemoryError: Java heap space
>         at java.base/java.util.Arrays.copyOf(Arrays.java:3745)
>         at 
> java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:172)
>         at 
> java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:748)
>         at java.base/java.lang.StringBuffer.append(StringBuffer.java:429)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.getStreamUpToMatchingBracket(NewAttributeBands.java:822)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextUnionCase(NewAttributeBands.java:304)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextLayoutElement(NewAttributeBands.java:237)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextAttributeElement(NewAttributeBands.java:184)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.parseLayout(NewAttributeBands.java:95)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.(NewAttributeBands.java:53)
>         at 
> ApacheCompress_1_22_90a4d8b3_OutOfMemory.main(ApacheCompress_1_22_90a4d8b3_OutOfMemory.java:7)
>  {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Resolved] (COMPRESS-628) OutOfMemoryError on pack200 NewAttributeBands.readNextUnionCase

2022-10-04 Thread Gary D. Gregory (Jira)


 [ 
https://issues.apache.org/jira/browse/COMPRESS-628?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Gary D. Gregory resolved COMPRESS-628.
--
Fix Version/s: 1.22
   Resolution: Fixed

[~infandrew] 

Thank you for your report.

Fixed in git master and snapshot builds in 
https://repository.apache.org/content/repositories/snapshots/.

Please test and close.

> OutOfMemoryError on pack200 NewAttributeBands.readNextUnionCase
> ---
>
> Key: COMPRESS-628
> URL: https://issues.apache.org/jira/browse/COMPRESS-628
> Project: Commons Compress
>  Issue Type: Bug
>  Components: Archivers
>Affects Versions: 1.21
> Environment: ubuntu18, java-11-openjdk-amd64
>Reporter: Andrii Hudz
>Priority: Major
> Fix For: 1.22
>
>
> Similar to https://issues.apache.org/jira/browse/COMPRESS-626
> pack200.NewAttributeBands.readNextUnionCase can result in an infinite loop 
> that finally leads to an out of memory error.
> {code:java}
> import org.apache.commons.compress.harmony.pack200.*;
> public class ApacheCompress_1_22_90a4d8b3_OutOfMemory {
> public static void main(String[] args) throws Exception {
> CPUTF8 name = new CPUTF8("");
> CPUTF8 layout = new CPUTF8("Re\\T");
> new NewAttributeBands(1, null, null,
> new AttributeDefinitionBands.AttributeDefinition(35, 
> AttributeDefinitionBands.CONTEXT_CLASS, name, layout)
> );
> }
> }
>  {code}
>  
> exception on 1.22 snapshot commit(90a4d8b3)
> {code:java}
> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space: 
> failed reallocation of scalar replaced objects {code}
> exception on  1.21
> {code:java}
> java.lang.OutOfMemoryError: Java heap space
>         at java.base/java.util.Arrays.copyOf(Arrays.java:3745)
>         at 
> java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:172)
>         at 
> java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:748)
>         at java.base/java.lang.StringBuffer.append(StringBuffer.java:429)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.getStreamUpToMatchingBracket(NewAttributeBands.java:822)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextUnionCase(NewAttributeBands.java:304)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextLayoutElement(NewAttributeBands.java:237)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextAttributeElement(NewAttributeBands.java:184)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.parseLayout(NewAttributeBands.java:95)
>         at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.(NewAttributeBands.java:53)
>         at 
> ApacheCompress_1_22_90a4d8b3_OutOfMemory.main(ApacheCompress_1_22_90a4d8b3_OutOfMemory.java:7)
>  {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Reopened] (RNG-164) Refactor SimpleSampler in SamplerBaseTest.java to improve test logic

2022-10-04 Thread Alex Herbert (Jira)


 [ 
https://issues.apache.org/jira/browse/RNG-164?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Herbert reopened RNG-164:
--

> Refactor SimpleSampler in SamplerBaseTest.java to improve test logic
> 
>
> Key: RNG-164
> URL: https://issues.apache.org/jira/browse/RNG-164
> Project: Commons RNG
>  Issue Type: Improvement
>  Components: sampling
>Reporter: Xiao Wang
>Priority: Minor
>
> h3. Description
> I noticed that there is a test class 
> [SimpleSampler|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SamplerBaseTest.java#L33]
>  extends production class 
> [SamplerBase|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L29]
>  to assist testing  
> [nextDouble()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L44],
>  
> [nextInt()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L51],
>  
> [nextInt(int)|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L59]
>  and 
> [nextLong()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L66].
>  This might not be the best priactice in unit testing and can be improved by 
> leveraging mocking frameworks.
> h3. Current Implementation
>  * {{SimpleSampler}} implements {{SamplerBase}} and overrides methods to call 
> super methods defined in parent class.
>  * In test case, the child test class is used to test methods in parent class 
> {{SamplerBase}}.
> h3. Proposed Implementation
>  * Replace {{SimpleSampler}} with a mocking object created by Mockito.
>  * Use method stub to control the behavior of the mocking object.
>  * Create a method to return the mocking object for reusing.
> h3. Motivation
>  * Decouple test class {{SimpleSampler}} from production class 
> {{SamplerBase}}.
>  * Remove the redundant test child class {{SimpleSampler}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Resolved] (RNG-164) Refactor SimpleSampler in SamplerBaseTest.java to improve test logic

2022-10-04 Thread Alex Herbert (Jira)


 [ 
https://issues.apache.org/jira/browse/RNG-164?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Herbert resolved RNG-164.
--
Fix Version/s: 1.5
   Resolution: Implemented

> Refactor SimpleSampler in SamplerBaseTest.java to improve test logic
> 
>
> Key: RNG-164
> URL: https://issues.apache.org/jira/browse/RNG-164
> Project: Commons RNG
>  Issue Type: Improvement
>  Components: sampling
>Reporter: Xiao Wang
>Priority: Minor
> Fix For: 1.5
>
>
> h3. Description
> I noticed that there is a test class 
> [SimpleSampler|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/test/java/org/apache/commons/rng/sampling/distribution/SamplerBaseTest.java#L33]
>  extends production class 
> [SamplerBase|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L29]
>  to assist testing  
> [nextDouble()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L44],
>  
> [nextInt()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L51],
>  
> [nextInt(int)|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L59]
>  and 
> [nextLong()|https://github.com/apache/commons-rng/blob/42a5151f9e2433ce84a6a77299cacbc389dcb870/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/SamplerBase.java#L66].
>  This might not be the best priactice in unit testing and can be improved by 
> leveraging mocking frameworks.
> h3. Current Implementation
>  * {{SimpleSampler}} implements {{SamplerBase}} and overrides methods to call 
> super methods defined in parent class.
>  * In test case, the child test class is used to test methods in parent class 
> {{SamplerBase}}.
> h3. Proposed Implementation
>  * Replace {{SimpleSampler}} with a mocking object created by Mockito.
>  * Use method stub to control the behavior of the mocking object.
>  * Create a method to return the mocking object for reusing.
> h3. Motivation
>  * Decouple test class {{SimpleSampler}} from production class 
> {{SamplerBase}}.
>  * Remove the redundant test child class {{SimpleSampler}}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (RNG-173) BaseProvider state filling procedure can be improved

2022-10-04 Thread Alex Herbert (Jira)


 [ 
https://issues.apache.org/jira/browse/RNG-173?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Herbert updated RNG-173:
-
Component/s: core

> BaseProvider state filling procedure can be improved
> 
>
> Key: RNG-173
> URL: https://issues.apache.org/jira/browse/RNG-173
> Project: Commons RNG
>  Issue Type: Improvement
>  Components: core
>Reporter: Alex Herbert
>Priority: Trivial
> Fix For: 1.5
>
>  Time Spent: 20m
>  Remaining Estimate: 0h
>
> The BaseProvider has a method to fill in remaining state if the input seed is 
> too short. The fill uses existing seed values to fill the remaining.
> The next state is created using:
> {code:java}
> long n = state[i - seed.length];
> state[i] = 1812433253L * (n ^ (n >> 30)) + i{code}
> If the existing state is zero then the new state is i. When the input seed 
> has no length then the filled state is a natural sequence.
> Here is a state of 10 filled from empty seeds of length 0 to 5:
> {noformat}
> 0: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
> 1: [0, 1, 1812433255, 3284914298392595265, 6102061520201954364, 
> -3308799481182342998, -3869692221293809580, -7101959917617921332, 
> 7986832403292652032, 8936067391732911773]
> 2: [0, 0, 2, 3, 3624866510, 5437299764, 6569828598597623783, 
> -8592001180344199076, 1136775338421644002, 8717367692712810396]
> 3: [0, 0, 0, 3, 4, 5, 5437299765, 7249733019, 9062166273, 
> -8592001182156632327]
> 4: [0, 0, 0, 0, 4, 5, 6, 7, 7249733020, 9062166274]
> 5: [0, 0, 0, 0, 0, 5, 6, 7, 8, 9]
> {noformat}
> When the seed is zero length or close to half the length of the desired state 
> and all zeros then the output state has a low number of non-zero bits.
> Note:
> This has little impact when using the Commons RNG simple module to create a 
> generator. The seed is produced to the correct length using a high quality 
> random source.
> A second issue is that the method to fill the state is an instance method. 
> Since it uses no state it could be a static method. I would suggest a method 
> to convert a seed to the correct length:
> {code:java}
> protected static long[] ensureSeedLength(long[] seed, int length); {code}
> This would allow classes that implement the following pattern:
> {code:java}
> MyRNG(long[] seed) {
>     if (seed.length < SEED_SIZE) {
>         final long[] state = new long[SEED_SIZE];
>         fillState(state, seed);
>         setState(state);
>     } else {
>         setState(seed);
>     }
> } {code}
> To simplify to:
> {code:java}
> MyRNG(long[] seed) {
>     setState(ensureSeedLength(seed, SEED_SIZE));
> }{code}
> h2. Compatibility
> The user guide states:
> {noformat}
> upon initialization, the underlying generation algorithm
> - may not use all the information contents of the seed,
> - may use a procedure (using the given seed as input) for further filling its 
> internal state (in order to avoid a too uniform initial state).
> In both cases, the behavior is not standard but should not change between 
> releases of the library (bugs notwithstanding).{noformat}
> Since behaviour *should not change* it would rule out changes for existing 
> classes. New classes could use the new static version to fill state.
> I would suggest providing a new method to ensure the input seed is a minimum 
> length. If the method seeds a SplitMix64 style generator with the first value 
> of the input seed (or zero if the seed length is zero) then the filled state 
> will be high quality. This type of generator only outputs zero once during 
> the period and so any seed length can be ensured to be non zero when it has 
> been expanded. An input seed of entirely zero values would be passed through 
> unchanged. This is the default *user beware* behaviour for full length zero 
> seeds.
> A 32-bit variant can be created using a similar hashing function that outputs 
> only a single 0 in the period, for example MurmurHash3's 32-bit finaliser 
> function.
> An example implementation for long values is:
> {code:java}
> private static final long GOLDEN_RATIO = 0x9e3779b97f4a7c15L
> protected static long[] ensureSeedLength(long[] seed, int length) {
>     if (seed.length < length) {
>         final long[] s = Arrays.copyOf(seed, length);
>         // Fill the rest as if using a SplitMix64 RNG
>         long x = s[0];
>         for (int i = seed.length; i < length; i++) {
>             s[i] = stafford13(x += GOLDEN_RATIO);
>         }
>         return s;
>     }
>     return seed;
> }
> private static long stafford13(long x) {
>     x = (x ^ (x >>> 30)) * 0xbf58476d1ce4e5b9L;
>     x = (x ^ (x >>> 27)) * 0x94d049bb133111ebL;
>     return x ^ (x >>> 31);
> }
> {code}
> A 32-bit mix function for Murmur32 is:
> {code:java}
> private static int murmur32(int x) {
>     x = (x ^ (x >>> 16)) * 0x85ebca6b;
>     x = (x ^ (x >>> 13)) * 

[jira] [Created] (COMPRESS-628) OutOfMemoryError on pack200 NewAttributeBands.readNextUnionCase

2022-10-04 Thread Andrii Hudz (Jira)
Andrii Hudz created COMPRESS-628:


 Summary: OutOfMemoryError on pack200 
NewAttributeBands.readNextUnionCase
 Key: COMPRESS-628
 URL: https://issues.apache.org/jira/browse/COMPRESS-628
 Project: Commons Compress
  Issue Type: Bug
  Components: Archivers
Affects Versions: 1.21
 Environment: ubuntu18, java-11-openjdk-amd64
Reporter: Andrii Hudz


Similar to https://issues.apache.org/jira/browse/COMPRESS-626

pack200.NewAttributeBands.readNextUnionCase can result in an infinite loop that 
finally leads to an out of memory error.


{code:java}
import org.apache.commons.compress.harmony.pack200.*;

public class ApacheCompress_1_22_90a4d8b3_OutOfMemory {
public static void main(String[] args) throws Exception {
CPUTF8 name = new CPUTF8("");
CPUTF8 layout = new CPUTF8("Re\\T");
new NewAttributeBands(1, null, null,
new AttributeDefinitionBands.AttributeDefinition(35, 
AttributeDefinitionBands.CONTEXT_CLASS, name, layout)
);
}
}
 {code}
 

exception on 1.22 snapshot commit(90a4d8b3)
{code:java}
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space: failed 
reallocation of scalar replaced objects {code}
exception on  1.21
{code:java}
java.lang.OutOfMemoryError: Java heap space
        at java.base/java.util.Arrays.copyOf(Arrays.java:3745)
        at 
java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:172)
        at 
java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:748)
        at java.base/java.lang.StringBuffer.append(StringBuffer.java:429)
        at 
org.apache.commons.compress.harmony.pack200.NewAttributeBands.getStreamUpToMatchingBracket(NewAttributeBands.java:822)
        at 
org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextUnionCase(NewAttributeBands.java:304)
        at 
org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextLayoutElement(NewAttributeBands.java:237)
        at 
org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextAttributeElement(NewAttributeBands.java:184)
        at 
org.apache.commons.compress.harmony.pack200.NewAttributeBands.parseLayout(NewAttributeBands.java:95)
        at 
org.apache.commons.compress.harmony.pack200.NewAttributeBands.(NewAttributeBands.java:53)
        at 
ApacheCompress_1_22_90a4d8b3_OutOfMemory.main(ApacheCompress_1_22_90a4d8b3_OutOfMemory.java:7)
 {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (RNG-180) New SplittableUniformRandomProvider interface

2022-10-04 Thread Alex Herbert (Jira)


 [ 
https://issues.apache.org/jira/browse/RNG-180?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Herbert updated RNG-180:
-
Component/s: (was: core)

> New SplittableUniformRandomProvider interface
> -
>
> Key: RNG-180
> URL: https://issues.apache.org/jira/browse/RNG-180
> Project: Commons RNG
>  Issue Type: New Feature
>  Components: client-api
>Affects Versions: 1.5
>Reporter: Alex Herbert
>Assignee: Alex Herbert
>Priority: Major
> Fix For: 1.5
>
>  Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The minimum java version for RNG is now 1.8. Stream support has been added 
> for the UniformRandomProvider and Sampler interfaces. These all operate using 
> a sequential stream. To use a parallel stream requires the concept of 
> splitting the source of randomness.
> I propose to add a Splittable interface. This can be modelled on the 
> interface in the JDK 17 random package [SplittableGenerator 
> (javadoc)|https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.SplittableGenerator.html]:
> {code:java}
> public interface SplittableUniformRandomProvider 
> extends UniformRandomProvider {
> SplittableUniformRandomProvider split();
>     SplittableUniformRandomProvider split(SplittableUniformRandomProvider 
> source);
>     Stream splits();
> Stream 
> splits(SplittableUniformRandomProvider source);
> Stream splits(long streamSize);
> Stream splits(long streamSize,
> SplittableUniformRandomProvider source);
> {code}
> The JDK interface has both a split and split(source) method, and similar for 
> the stream created by repeat splitting. The source is to provide the random 
> bits to initialise the new instances. In most cases this will just be the 
> current instance. However it provides a means to provide a small state 
> splittable generator for the random source of bits and use a larger state 
> generator to provide new instances from those bits, or vice versa. This 
> allows more flexibility to control the source of random bits, and the 
> instance type of the new split generators.
> Note: It is possible to implement the entire interface using default methods 
> except:
> {code:java}
>     SplittableUniformRandomProvider split(SplittableUniformRandomProvider 
> source);
> {code}
> The stream can be created by recursively splitting the current instance via a 
> custom Spliterator.
> Also note that the stream methods in UniformRandomProvider can be overridden 
> to support parallel streams. This requires for example a custom 
> Spliterator.OfInt to split the generator for parallel generation.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (RNG-182) Bill of Materials (BOM)

2022-10-04 Thread Alex Herbert (Jira)


 [ 
https://issues.apache.org/jira/browse/RNG-182?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Herbert updated RNG-182:
-
Component/s: bom

> Bill of Materials (BOM)
> ---
>
> Key: RNG-182
> URL: https://issues.apache.org/jira/browse/RNG-182
> Project: Commons RNG
>  Issue Type: New Feature
>  Components: bom, client-api, core, sampling, simple
>Affects Versions: 1.5
>Reporter: Alex Herbert
>Assignee: Alex Herbert
>Priority: Minor
> Fix For: 1.5
>
>
> In 1.5 the multi-module project rearranges a few methods to default interface 
> methods in a different module. This is binary compatible. However it requires 
> that all versions of the modules are matched. If the other modules are 
> explicitly imported by a transitive dependency as a lower version then this 
> will cause a runtime error due to missing methods.
>  
> I suggest we create a Bill of Materials (BOM) as a separate artifact to be 
> deployed to maven for dependency management. Downstream users can then 
> include this in their POM and all versions of the RNG modules would be 
> matched.
> {noformat}
> 
>     
>         
>             org.apache.commons
>             commons-rng-bom
>             1.5
>             pom
>             import
>         
>     
> 
> {noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Updated] (RNG-176) Enhance the UniformRandomProvider interface with extra methods and default implementations

2022-10-04 Thread Alex Herbert (Jira)


 [ 
https://issues.apache.org/jira/browse/RNG-176?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Alex Herbert updated RNG-176:
-
Component/s: client-api

> Enhance the UniformRandomProvider interface with extra methods and default 
> implementations
> --
>
> Key: RNG-176
> URL: https://issues.apache.org/jira/browse/RNG-176
> Project: Commons RNG
>  Issue Type: New Feature
>  Components: client-api
>Affects Versions: 1.4
>Reporter: Alex Herbert
>Assignee: Alex Herbert
>Priority: Major
> Fix For: 1.5
>
>  Time Spent: 50m
>  Remaining Estimate: 0h
>
> JDK 17 introduced the {{RandomGenerator}} interface with the following 
> methods:
> {code:java}
> DoubleStream doubles();
> DoubleStream doubles(double randomNumberOrigin, double randomNumberBound);
> DoubleStream doubles(long streamSize);
> DoubleStream doubles(long streamSize, double randomNumberOrigin,
>  double randomNumberBound);
> IntStream ints();
> IntStream ints(int randomNumberOrigin, int randomNumberBound);
> IntStream ints(long streamSize);
> IntStream ints(long streamSize, int randomNumberOrigin,
>int randomNumberBound);
> LongStream longs();
> LongStream longs(long randomNumberOrigin, long randomNumberBound);
> LongStream longs(long streamSize);
> LongStream longs(long streamSize, long randomNumberOrigin,
>  long randomNumberBound);
> boolean nextBoolean();
> void nextBytes(byte[] bytes);
> float nextFloat();
> float nextFloat(float bound);
> float nextFloat(float origin, float bound);
> double nextDouble();
> double nextDouble(double bound);
> double nextDouble(double origin, double bound);
> int nextInt();
> int nextInt(int bound);
> int nextInt(int origin, int bound);
> long nextLong();
> long nextLong(long bound);
> long nextLong(long origin, long bound);
> double nextGaussian();
> double nextGaussian(double mean, double stddev);
> double nextExponential();
> {code}
> The only method that is *non-default* is {{{}nextLong{}}}. This allows a new 
> generator to be simply implemented by providing the source of randomness as 
> 64-bit longs.
> The {{UniformRandomProvider}} interface can be expanded to include these 
> generation methods. Using Java 8 default interface methods will not require 
> any changes to generators currently implementing the interface.
> I propose to:
>  # Add the new methods for streams and numbers in a range.
>  # Add default implementations of the current API. These can be extracted 
> from the  o.a.c.rng.core.BaseProvider implementations.
>  # Remove the implementations in o.a.c.rng.core.BaseProvider. This change 
> would be binary compatible.
> The base classes in commons core for 32-bit and 64-bit sources of randomness, 
> IntProvider and LongProvider, can be updated suitably to only override the 
> default interface methods where they can be more efficiently implemented 
> given the source of randomness. This applies to:
> ||Source||Update||Details||
> |int|nextBytes|Use nextInt() for the source of bytes|
> | |nextBoolean|Use a cached int for the randomness|
> | |nextInt|Directly supply the int rather than using 32-bits from nextLong()|
> | |nextDouble|Optimise the bits used from two ints for the 53-bits required 
> for the double.|
> |long|nextInt; nextBoolean|Use a cached long for the randomness|
> h3. Note 1
> The UniformRandomProvider also has the method:
> {code:java}
> void nextBytes(byte[] bytes,
>int start,
>int len);
> {code}
> This can also have a default implementation using the output from nextLong().
> h3. Note 2
> The methods to generate an exponential and Gaussian are already implemented 
> in the {{commons-rng-sampling}} module.
> java.util.Random has a nextGaussian() method and so this method appears to be 
> for backward compatibility with legacy Java code. The method is implemented 
> using a modified Ziggurat sampler which uses an exponential sampler for the 
> long tail. The API has thus exposed the exponential sampling method that is 
> used internally in the nextGaussian implementation.
> With no backward compatibility requirements the Commons RNG interface can 
> avoid the distribution sampling methods. Users should select an appropriate 
> sampler from the sampling module.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Closed] (COMPRESS-626) OutOfMemoryError on malformed pack200 attributes

2022-10-04 Thread Andrii Hudz (Jira)


 [ 
https://issues.apache.org/jira/browse/COMPRESS-626?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andrii Hudz closed COMPRESS-626.


> OutOfMemoryError on malformed pack200 attributes
> 
>
> Key: COMPRESS-626
> URL: https://issues.apache.org/jira/browse/COMPRESS-626
> Project: Commons Compress
>  Issue Type: Bug
>  Components: Archivers
>Affects Versions: 1.21
> Environment: ubuntu18
> java-11-openjdk-amd64
>Reporter: Andrii Hudz
>Priority: Major
> Fix For: 1.22
>
> Attachments: sample-1.0-SNAPSHOT-vulnerable-pack200.jar
>
>
> pack200.NewAttributeBands.getStreamUpToMatchingBracket() and 
> unpack200.NewAttributeBands.getStreamUpToMatchingBracket can result in an 
> infinite loop that finally leads to an out of memory error.
> pack example:
> {code:java}
> import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands;
> import org.apache.commons.compress.harmony.pack200.CPUTF8;
> import org.apache.commons.compress.harmony.pack200.NewAttributeBands;
> public class ApacheCompress_1_21_OutOfMemory {
> public static void main(String[] args) throws Exception {
> CPUTF8 name = new CPUTF8("");
> CPUTF8 layout = new CPUTF8("[");
> new NewAttributeBands(1, null, null,
> new AttributeDefinitionBands.AttributeDefinition(35, 
> AttributeDefinitionBands.CONTEXT_CLASS, name, layout)
> );
> }
> }{code}
> {code:java}
> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at 
> java.base/java.util.Arrays.copyOf(Arrays.java:3745)     at 
> java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:172)
>      at 
> java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:748)
>      at java.base/java.lang.StringBuffer.append(StringBuffer.java:429)     at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.getStreamUpToMatchingBracket(NewAttributeBands.java:822)
>      at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextAttributeElement(NewAttributeBands.java:180)
>      at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.parseLayout(NewAttributeBands.java:95)
>      at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.(NewAttributeBands.java:53)
>      at 
> ApacheCompress_1_21_OutOfMemory.main(ApacheCompress_1_21_OutOfMemory.java:9)
> {code}
>  
> unpack example on the malformed archive:
> {code:java}
> import org.apache.commons.compress.java.util.jar.Pack200;
> public class ApacheCompress_1_21_OutOfMemory_unpack_demo {
> public static void main(String[] args) throws Exception {
> String input = "/sample-1.0-SNAPSHOT-vulnerable-pack200.jar";
> try (
> InputStream inputStream = 
> ApacheCompress_1_21_OutOfMemory_unpack_demo.class.getResourceAsStream(input);
> JarOutputStream out = new JarOutputStream(new OutputStream() {
> @Override
> public void write(int i) {
> }
> });
> ) {
> Pack200.newUnpacker().unpack(inputStream, out);
> }
> }
> }{code}
> {code:java}
> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at 
> java.base/java.util.Arrays.copyOf(Arrays.java:3745)     at 
> java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:172)
>      at 
> java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:748)
>      at java.base/java.lang.StringBuffer.append(StringBuffer.java:429)     at 
> org.apache.commons.compress.harmony.unpack200.NewAttributeBands.getStreamUpToMatchingBracket(NewAttributeBands.java:883)
>      at 
> org.apache.commons.compress.harmony.unpack200.NewAttributeBands.readNextAttributeElement(NewAttributeBands.java:201)
>      at 
> org.apache.commons.compress.harmony.unpack200.NewAttributeBands.parseLayout(NewAttributeBands.java:122)
>      at 
> org.apache.commons.compress.harmony.unpack200.NewAttributeBands.(NewAttributeBands.java:58)
>      at 
> org.apache.commons.compress.harmony.unpack200.AttrDefinitionBands.read(AttrDefinitionBands.java:85)
>      at 
> org.apache.commons.compress.harmony.unpack200.Segment.readSegment(Segment.java:353)
>      at 
> org.apache.commons.compress.harmony.unpack200.Segment.unpackRead(Segment.java:459)
>      at 
> org.apache.commons.compress.harmony.unpack200.Segment.unpack(Segment.java:436)
>      at 
> org.apache.commons.compress.harmony.unpack200.Archive.unpack(Archive.java:156)
>      at 
> org.apache.commons.compress.harmony.unpack200.Pack200UnpackerAdapter.unpack(Pack200UnpackerAdapter.java:49)
>      at 
> 

[jira] [Commented] (COMPRESS-626) OutOfMemoryError on malformed pack200 attributes

2022-10-04 Thread Andrii Hudz (Jira)


[ 
https://issues.apache.org/jira/browse/COMPRESS-626?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17612547#comment-17612547
 ] 

Andrii Hudz commented on COMPRESS-626:
--

Fixed

> OutOfMemoryError on malformed pack200 attributes
> 
>
> Key: COMPRESS-626
> URL: https://issues.apache.org/jira/browse/COMPRESS-626
> Project: Commons Compress
>  Issue Type: Bug
>  Components: Archivers
>Affects Versions: 1.21
> Environment: ubuntu18
> java-11-openjdk-amd64
>Reporter: Andrii Hudz
>Priority: Major
> Fix For: 1.22
>
> Attachments: sample-1.0-SNAPSHOT-vulnerable-pack200.jar
>
>
> pack200.NewAttributeBands.getStreamUpToMatchingBracket() and 
> unpack200.NewAttributeBands.getStreamUpToMatchingBracket can result in an 
> infinite loop that finally leads to an out of memory error.
> pack example:
> {code:java}
> import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands;
> import org.apache.commons.compress.harmony.pack200.CPUTF8;
> import org.apache.commons.compress.harmony.pack200.NewAttributeBands;
> public class ApacheCompress_1_21_OutOfMemory {
> public static void main(String[] args) throws Exception {
> CPUTF8 name = new CPUTF8("");
> CPUTF8 layout = new CPUTF8("[");
> new NewAttributeBands(1, null, null,
> new AttributeDefinitionBands.AttributeDefinition(35, 
> AttributeDefinitionBands.CONTEXT_CLASS, name, layout)
> );
> }
> }{code}
> {code:java}
> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at 
> java.base/java.util.Arrays.copyOf(Arrays.java:3745)     at 
> java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:172)
>      at 
> java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:748)
>      at java.base/java.lang.StringBuffer.append(StringBuffer.java:429)     at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.getStreamUpToMatchingBracket(NewAttributeBands.java:822)
>      at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.readNextAttributeElement(NewAttributeBands.java:180)
>      at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.parseLayout(NewAttributeBands.java:95)
>      at 
> org.apache.commons.compress.harmony.pack200.NewAttributeBands.(NewAttributeBands.java:53)
>      at 
> ApacheCompress_1_21_OutOfMemory.main(ApacheCompress_1_21_OutOfMemory.java:9)
> {code}
>  
> unpack example on the malformed archive:
> {code:java}
> import org.apache.commons.compress.java.util.jar.Pack200;
> public class ApacheCompress_1_21_OutOfMemory_unpack_demo {
> public static void main(String[] args) throws Exception {
> String input = "/sample-1.0-SNAPSHOT-vulnerable-pack200.jar";
> try (
> InputStream inputStream = 
> ApacheCompress_1_21_OutOfMemory_unpack_demo.class.getResourceAsStream(input);
> JarOutputStream out = new JarOutputStream(new OutputStream() {
> @Override
> public void write(int i) {
> }
> });
> ) {
> Pack200.newUnpacker().unpack(inputStream, out);
> }
> }
> }{code}
> {code:java}
> Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at 
> java.base/java.util.Arrays.copyOf(Arrays.java:3745)     at 
> java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:172)
>      at 
> java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:748)
>      at java.base/java.lang.StringBuffer.append(StringBuffer.java:429)     at 
> org.apache.commons.compress.harmony.unpack200.NewAttributeBands.getStreamUpToMatchingBracket(NewAttributeBands.java:883)
>      at 
> org.apache.commons.compress.harmony.unpack200.NewAttributeBands.readNextAttributeElement(NewAttributeBands.java:201)
>      at 
> org.apache.commons.compress.harmony.unpack200.NewAttributeBands.parseLayout(NewAttributeBands.java:122)
>      at 
> org.apache.commons.compress.harmony.unpack200.NewAttributeBands.(NewAttributeBands.java:58)
>      at 
> org.apache.commons.compress.harmony.unpack200.AttrDefinitionBands.read(AttrDefinitionBands.java:85)
>      at 
> org.apache.commons.compress.harmony.unpack200.Segment.readSegment(Segment.java:353)
>      at 
> org.apache.commons.compress.harmony.unpack200.Segment.unpackRead(Segment.java:459)
>      at 
> org.apache.commons.compress.harmony.unpack200.Segment.unpack(Segment.java:436)
>      at 
> org.apache.commons.compress.harmony.unpack200.Archive.unpack(Archive.java:156)
>      at 
> org.apache.commons.compress.harmony.unpack200.Pack200UnpackerAdapter.unpack(Pack200UnpackerAdapter.java:49)
>      at 
>